473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

App_GlobalResources & Resources namespace

I've upgraded a .Net 1.1 web app to 2.0 and am having a heck of a time
getting resources to work again. From what I understand if I move my
strings.resx file into the App_GlobalResources folder I should magically be
able to reference my strings using the syntax Resources.strings.string1.
This isn't working for me. Is there something I'm missing other than moving
the file itself and rebuilding? I get this error:

"The type or namespace name 'strings' does not exist in the namespace
'System.Resources' (are you missing an assembly reference?)"

-Brett-

Mar 21 '06 #1
6 23810


Hi,

Thanks for posting at the newsgroup!

ASP.net 2.0 has introduced one code compilation model, very different from
the ASP.net 1.1. For the resource management, ASP.net 2.0 will generate one
namespace Resources for the resources located under the folder
"App_GlobalResources". For each resource (string, image etc) at the
resource file, ASP.net will dynamically generate the static property for
each.

For example, we can add one Resource.resx file at the web application
project located under App_GlobalResources. Then we define one string called
"MySiteTitle" at the resoruce designer. Then we can write the code below to
access this string resource:
String mysitename = Resources.Resource.MySiteTitle;

The Resources namespace is dynamically generated by ASP.net 2.0. And the
second part of the resource name is the resx file name. If we chnage the
resource name to HappyANiceDayResource.resx, ASP.net 2.0 will dynamically
the correspond name and we can access the string resource as below:
String mysitename = Resources.HappyANiceDayResource.MySiteTitle;

This design will be quite easy for us to locate the resource. For your
application migrated from ASP.net 1.1, I'd suggest please change the code
to locate the resources.

In addition, I'd suggest please this article will be of great help for you
to migrate the application from ASP.net 1.1 to ASP.net 2.0:
ASP.NET 2.0 Migration Overview
http://msdn2.microsoft.com/en-us/library/ms227549.aspx

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.
Mar 21 '06 #2
I appreciate the effort to help me here, but frankly if you'd read my post
you'd see I am aware of how this is supposed to work. I'm saying it is not
working for me. I'm looking for a little assistance on what I might be
doing wrong. Let me give a little more detail.

When VS05 converted my ASP.Net 1.1 app to 2.0 it created the
App_GlobalResources folder and moved my one string resource (resx) file into
it. For some reason I was unable to open the resx file in the designer so I
went ahead and created a new one and copied all of my strings into it (then
deleted the original). My resx file is named strings.en.resx and is located
in the App_GlobalResources subfolder.

In my code-behind file if I try to use the syntax:
Resources.strings.en.mystring I am getting compilation errors stating
'Resources' does not exist in the current context.

So is there something I'm missing here? VS05 does not appear to be creating
the typed dataset for my string file.

-Brett-

""Wei-Dong XU [MSFT]"" <v-****@online.microsoft.com> wrote in message
news:FM**************@TK2MSFTNGXA03.phx.gbl...


Hi,

Thanks for posting at the newsgroup!

ASP.net 2.0 has introduced one code compilation model, very different from
the ASP.net 1.1. For the resource management, ASP.net 2.0 will generate
one
namespace Resources for the resources located under the folder
"App_GlobalResources". For each resource (string, image etc) at the
resource file, ASP.net will dynamically generate the static property for
each.

For example, we can add one Resource.resx file at the web application
project located under App_GlobalResources. Then we define one string
called
"MySiteTitle" at the resoruce designer. Then we can write the code below
to
access this string resource:
String mysitename = Resources.Resource.MySiteTitle;

The Resources namespace is dynamically generated by ASP.net 2.0. And the
second part of the resource name is the resx file name. If we chnage the
resource name to HappyANiceDayResource.resx, ASP.net 2.0 will dynamically
the correspond name and we can access the string resource as below:
String mysitename = Resources.HappyANiceDayResource.MySiteTitle;

This design will be quite easy for us to locate the resource. For your
application migrated from ASP.net 1.1, I'd suggest please change the code
to locate the resources.

In addition, I'd suggest please this article will be of great help for you
to migrate the application from ASP.net 1.1 to ASP.net 2.0:
ASP.NET 2.0 Migration Overview
http://msdn2.microsoft.com/en-us/library/ms227549.aspx

Please feel free to let me know if you have any further question on this
issue.

Have a nice day!

Best Regards,
Wei-Dong XU
Microsoft Support
---------------------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no
rights.
---------------------------------------------------------------------------
It is my pleasure to be of any assistance.

Mar 21 '06 #3
Hi Brett,

As for the ASP.NET 2.0 localization and resource handling, it hasn't change
much from the original one. For the resource file, e.g .resx or .txt file,
their file name should not contain any cultureInfo name(such as "en",
"fr-Fr", this is used for the runtime to idenitity them as the same
resource for a specific language/culture.

For example, if we have the following resource files:

MyResources.strings.resx

MyResources.strings.en.resx

MyResources.strings.fr.resx
They're actually a single resource item, just of different
culture/language. At runtime in the code, we just use the following
statement to retrieve value from the above resource file:
Response.Write(Resources.MyResources.strings.XXXXX )

(no prefix like "en" or "fr" or....)

and which file to use depend on the current thread's UICulture.

For example, if we add the following code to manually set the thread's
CurrentUICulture:

============
protected void Page_Load(object sender, EventArgs e)
{

System.Threading.Thread.CurrentThread.CurrentUICul ture = new
System.Globalization.CultureInfo("fr-FR");

Response.Write(Resources.MyResources.strings.XXXXX )

============

the above code will read the resource string from the
MyResource.strings.fr.resx file.

You can also get some further description in the MSDN document on ASP.NET
global/localization:
#ASP.NET Globalization and Localization
http://msdn2.microsoft.com/en-us/library/c6zyy3s9.aspx

#Walkthrough: Using Resources for Localization with ASP.NET
http://msdn2.microsoft.com/en-us/library/fw69ke6f.aspx

Hope all these help you.
Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 22 '06 #4
It turns out my problem came down to the fact that my resource file was
named simply 'strings.en.resx'. For some reason Visual Studio doesn't deal
with that as documented (in generating the typesafe dataset). If I change
the name to something like MyResources.string.en.resx then everything works
as documented.

This was just one of those crazy bang your head against the wall kindof
problems. I was doing everything as documented but apparently chose a name
that either has special meaning or is involved in a bug of some sort.

Thanks for the help...

-Brett-

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:tr**************@TK2MSFTNGXA03.phx.gbl...
Hi Brett,

As for the ASP.NET 2.0 localization and resource handling, it hasn't
change
much from the original one. For the resource file, e.g .resx or .txt file,
their file name should not contain any cultureInfo name(such as "en",
"fr-Fr", this is used for the runtime to idenitity them as the same
resource for a specific language/culture.

For example, if we have the following resource files:

MyResources.strings.resx

MyResources.strings.en.resx

MyResources.strings.fr.resx
They're actually a single resource item, just of different
culture/language. At runtime in the code, we just use the following
statement to retrieve value from the above resource file:
Response.Write(Resources.MyResources.strings.XXXXX )

(no prefix like "en" or "fr" or....)

and which file to use depend on the current thread's UICulture.

For example, if we add the following code to manually set the thread's
CurrentUICulture:

============
protected void Page_Load(object sender, EventArgs e)
{

System.Threading.Thread.CurrentThread.CurrentUICul ture = new
System.Globalization.CultureInfo("fr-FR");

Response.Write(Resources.MyResources.strings.XXXXX )

============

the above code will read the resource string from the
MyResource.strings.fr.resx file.

You can also get some further description in the MSDN document on ASP.NET
global/localization:
#ASP.NET Globalization and Localization
http://msdn2.microsoft.com/en-us/library/c6zyy3s9.aspx

#Walkthrough: Using Resources for Localization with ASP.NET
http://msdn2.microsoft.com/en-us/library/fw69ke6f.aspx

Hope all these help you.
Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 22 '06 #5
Thanks for your followup Brett,

Yes, I admit that the document still need much improvement since it lacks
good and complete samples or explanation on some common scenario. Anyway,
if you meet any problem, please feel free to post here, we will be happy to
be of assistance.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 23 '06 #6
Hi,
I migrated a web application that was created in VS2003 to VS2005.
I am trying to access migrated resources using Resources.Resurce.Resourcemanager.GetString(resour ceName), but it says "The name 'Resources' does not exist in the current context"

I have encountered this error before, when i migrated a website to VS2005.
But when i add a resx file to project, it automatically added "resources referance" to my website project. And i was able to use my old resx files, with resources namespace.

But when i do this in the new project i migrated, it does not add "resources referance"

From where and how can i add "resources referance" to my project?
May 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
4
by: António Pinho | last post by:
Hi, I have a big problem with an webpart/assembly. i'm trying to connect to sql server but i get the error "Request for the permission of type System.Data.SqlClient.SqlClientPermission,...
13
by: Adam | last post by:
Trying to get an asp.net 2.0 app running and am receiving this error. I see a bunch of people with this error on the net, but no solution: Works fine on my local machine, deployed to a server it...
0
by: Jody Gelowitz | last post by:
VS2005 Standard Edition WinXP Pro SP2 I have setup a Web project under: http://localhost/myproject/ and have received a "Failed to map the path '/MyProject/App_GlobalResources'." error...
1
by: kurt sune | last post by:
This drives me nuts,I have put a textfile in App_GlobalResources. How do I read it in runtime? I have googled for two days now. GetExecutingAssembly.GetManifestResourceStream("XYZ.xml") returns...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: C. Moya | last post by:
When sites are published, App_GlobalResources seems to be compiled and is not updateable (even though you set "Allow this precompiled site to be updateable"). Is there any way to update global...
4
by: nils.harrison | last post by:
I would like to list/enumerate all the strings in my resources files in an ASP.NET 2.0 web application, for my own personal convenience. I just want to be able to display the information key1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.