Click here to Skip to main content
15,916,188 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi.

i'm trying to access the properties.resources in vs 2010 windows form to return a specif file, but whithout specifing the address as shown bellow

my code is this:

C#
public Stream Files(string resource, string extension)
       {
           switch (extension)
           {
              case "htm":
                   if ((String.Compare(resource, "index") != 0) && (String.Compare(resource, "login") != 0))
                   {
                       if (!Authenticate()) return null;
                   }
                   WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
                   break;
               case "js":
                   WebOperationContext.Current.OutgoingResponse.ContentType = "text/javascript";
                   break;
               case "css":
                   WebOperationContext.Current.OutgoingResponse.ContentType = "text/css";
                   break;
               case "png":
                   WebOperationContext.Current.OutgoingResponse.ContentType = "image/png";
                   break;
               case "ico":
                   WebOperationContext.Current.OutgoingResponse.ContentType = "image/x-icon";
                   break;
               default:
                   WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.UnsupportedMediaType;
                   return new MemoryStream(Encoding.ASCII.GetBytes("File type not supported"), false);
           }
           string fileName = String.Format(@"C:\Users\Lopez\Documents\visual studio 2010\Projects\Hello\Hello\Resources\{0}.{1}", resource, extension);
           return new FileStream(fileName, FileMode.Open);
       }


My problem is how to change this part
string fileName = String.Format(@"C:\Users\Lopez\Documents\visual studio 2010\Projects\Hello\Hello\Resources\{0}.{1}", resource, extension);


in something like

Hello.Properties.Resources.state


thk
Posted
Comments
TryAndSucceed 2-Oct-13 10:58am    
Are you trying to set the Path of the filename by adding a parameter in web.config and not write it up everytime?

1 solution

i don't have that file, i'm working in a windows form that as implemented a web server (local). the htm files are being showed in a webbrowser component in the form.
my ideia was after the switch case, somehow call the file that i want without defining a specific address (my machine). the point is to run the application in other computers, for that i cannot have this path
C:\Users\Lopez\Documents\visual studio 2010\Projects\Hello\Hello\Resources\
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900