[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

Using a resource file in c# windows application

Hello,
I am developing a usercontrol which holds a web browser control and has a combo box. The combo box is used to navigate to different files to be loaded in the web browser. Presently, I have my combo box reading a folder(using the file system object) to  get the actual  files (Word Templates).
I do not want to hard code the directory path into my usercontrol but want to make use of a resource file which will actually hold my templates and not ordinary names.  Please note that the web browser control takes a string(url) as a parameter to navigate to the specified location. I just want my control to be independent and not coupled to a folder path.

This is a windows application using C#.

How can I handle this please ?

Thanks.
0
Sirdots
Asked:
Sirdots
  • 7
  • 5
1 Solution
 
dunglaCommented:
0
 
SirdotsAuthor Commented:
Thanks a lot. This is not working for me. I checked this and looks like it takes files like bitmap, icon,string and image list. I actually want a document(e.g mytemplate.dot) and not an ordinary name i typed in a text file. They are two different things. My templates reside in a folder and i want them to be part of the application when deployed.

Thanks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jatinderalaghCommented:
>>I do not want to hard code the directory path into my usercontrol but want to make use of a resource file which will actually hold my templates and not ordinary names.

Can you explain more?
0
 
SirdotsAuthor Commented:
Here is the click event for my Go command button which accepts the value selected from a combo box and passes it to the web browser .

private void cmdGo_Click(object sender, System.EventArgs e)
            {
                  //Pick the various Templates here
                  
                  string _strFileName;
                string _processStrFileName;

                  //Get the string name that was selected from here
                  _strFileName = cmbTemplates.SelectedItem.ToString();

                  //Pass the string name selected to a path
                  _processStrFileName = "c:\\Templates\\" + _strFileName + ".dot";
                        
                  
                  if (_processStrFileName != null)
                  {
                        object refmissing = System.Reflection.Missing.Value;
                        oDocument = null;
                        axWebBrowser1.Navigate(_processStrFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
                  }
            }


Now, since I have my web browser control  being developed  as a user control, I want it to be independent, I want the folder where the templates reside to be shipped or deployed with the application and should be able to accept updates from time to time i.e adding more templates and modifying existing templates.

I want the c:\Templates and the template files (template1.dot) to be part of my windows application. I dont want to go to other desktop to start creating C:\Templates before my user control can work

Is this clear??

0
 
jatinderalaghCommented:
So you can make Templates folder as a part of deployment and make it a directory in your deployment folder.
So you will always has to search for path like
string strPath = @"\Templates\"+"FileName";

how come resource files will solve your problem.
0
 
SirdotsAuthor Commented:
Thanks. I am not saying resource file will solve my problem. I am actually asking for a best way to do this and used resource file as an example. I think you now understand what I mean.
0
 
jatinderalaghCommented:
Better way will be have an XML file or Config file in deployment directory and from this XML or config file you can read the Template path.

Why it will be a better way:
 as you can even have multiple directories and also it does not require you to hard code the path.
So your directory information will be always generated at run time. No dependencies. User can modify these at will.
0
 
SirdotsAuthor Commented:
How can I achieve this by code?

Thanks.
0
 
jatinderalaghCommented:
Have a look on this accepted answer. your problem seems to be quite similar.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21277109.html

Jatinder
0
 
SirdotsAuthor Commented:
Thanks for all your help. Maybe I should put it this way. Xml file will read names of the files. I actually need to read the files(real files)  which exist in a folder to the combo box and user hits the go button to load that template on my web browser. How can I read the original files from this folder into an xml file setting a path to this folder so I can get the exact files and not names of the files. In this case, the path will now exist in an xml file and not  hardcoded in my code.
0
 
jatinderalaghCommented:
Your xml file wil be having path to templates directory.

say string Path = @"c:\templates";

And now you want to retrive the list of .dot files in this directory.

use the System.IO namespace

DirectoryInfo dir = new DirectoryInfo(Path);
        foreach (FileInfo f in dir.GetFiles("*.dot"))
        {
// FullName property provides you the complete path.
// And Name property will provide you only the name of file
            String name = f.FullName;
            long size = f.Length;
            DateTime creationTime = f.CreationTime;
            Console.WriteLine("{0,-12:N0} {1,-20:g} {2}", size,
                creationTime, name);
        }

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now