473,386 Members | 1,810 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,386 software developers and data experts.

OpenFileDialog Is Messing With My .Resources File Path [Win C#]

Hi everyone,

I"m having a problem with the OpenFileDialog() changing my path to save to
my .resources file. I'm a bit baffled why this is happening, even when I
set the OpenFileDialog back to the inital directory where the .resource file
resides.

What I am trying to do is get the location of my database and save it to
string format in my resource file (un-embedded). When I go to save this
information to my .resouce file it creates another resource file at the
location that I selected the database from and not the origional one. Now
this problem does not a rise when I manually type in to my textbox the
location of my database.

A sample of my OpenFileDialog() is as follows, then my Save to .resource
file:

//SET-UP DATABASE LOCATION

private void DB_Connection_Click(object sender, System.EventArgs e)

{

OpenFileDialog dlg = new OpenFileDialog();

dlg.InitialDirectory = Application.StartupPath;

dlg.Filter = ".MDB Files (*.mdb)|*.mdb";

dlg.ReadOnlyChecked = true;

dlg.ShowReadOnly = true;

if(dlg.ShowDialog() == DialogResult.OK)

{

this.txtBox_DB_Connection.Text = dlg.FileName;

}

//RESET

dlg.RestoreDirectory = true;

dlg.Dispose();

}

****************************************

//RETURN FROM TECH ZONE FOR UPDATES

private void Tech_Return(string Host_BackEnd,string Connection,string
Machine_Name,string Station_Printer,string Adverts,string Bar_Printer)

{

ResourceWriter Writer = new ResourceWriter("HOST.resources");

//

Writer.AddResource("HOST_BACKEND", Host_BackEnd);

Writer.AddResource("DB CONNECTION", Connection);

Writer.AddResource("MACHINE NAME", Machine_Name);

Writer.AddResource("STATION PRINTER", Station_Printer);

Writer.AddResource("COMMERCIAL", Adverts);

//JUST MORE OF THE SAME HERE

//

Writer.Generate();

Writer.Close();

Writer.Dispose();

}
I'm not sure what I"m missing or is going wrong here, so any and all help is
appreciated.

Thank you all in advance.
Feb 1 '08 #1
2 4700
On Fri, 01 Feb 2008 07:52:07 -0800, MikeY <mi*******@yahoo.comwrote:
I"m having a problem with the OpenFileDialog() changing my path to save
to
my .resources file. I'm a bit baffled why this is happening, even when I
set the OpenFileDialog back to the inital directory where the .resource
file
resides.
You need to set RestoreDirectory _before_ you show the dialog. Not after.

For what it's worth, I don't think it's a good idea for your resource
handling code to depend on the current directory anyway. You should
determine the actual path when your application starts, and then always
reference the file via that absolute path.

Pete
Feb 1 '08 #2
Hi Peter,

Thank you that exactly solved my problem. As for determining the actual
path. I shall take your advice and look into it right now.

Thanks again

MikeY

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Fri, 01 Feb 2008 07:52:07 -0800, MikeY <mi*******@yahoo.comwrote:
>I"m having a problem with the OpenFileDialog() changing my path to save
to
my .resources file. I'm a bit baffled why this is happening, even when I
set the OpenFileDialog back to the inital directory where the .resource
file
resides.

You need to set RestoreDirectory _before_ you show the dialog. Not after.

For what it's worth, I don't think it's a good idea for your resource
handling code to depend on the current directory anyway. You should
determine the actual path when your application starts, and then always
reference the file via that absolute path.

Pete

Feb 1 '08 #3

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

Similar topics

0
by: yongwei | last post by:
After I make some changes to my program, I got a run time error each time, see following. Seems to me like the compiler did not create a GraphicInput.resources in \obj sub dir. the compiler did...
1
by: Stefan Turalski \(stic\) | last post by:
Hi, What I need to do is adding some support for resources files to my application. What I did is: MyAppMain <- startup project MyAppHelper <- project which has MyAppResourcesClass (al a...
1
by: fabrice | last post by:
Hello, I'm trying to use Resources file to manipulate language in my application Web. I'm using vb.net and framewok 1.1. I have read some articles about the subject. But i don't understand...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
3
by: John Torville | last post by:
Hi there, Does anyone know how to add ".txt" resources file to a C# project in Visual Studio. It should compile down to an embedded ".resources" file the same way as a ".resx" file. Thanks.
0
by: Henry Jan | last post by:
Hi All, In VS2005, when I use compilation directive for namespace that contains a control Control1 class, e.g.: #if _Version_A_ namespace Component.Windows.ASuite #elif _Version_B_ ...
4
by: GS | last post by:
How do I fix this corrupt resource file header problem? Corrupt .resources file. Got an unexpected EndOfStreamException while trying to read the ResourceReader header. When I open up properties,...
1
by: stormogulen | last post by:
Hi, I have converted a project from VS2005 to VS2008, and I now have problems accessing icons which are stored in a .resources file. The target framework is still 2.0. When I look at the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.