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

M

MikeY

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.
 
P

Peter Duniho

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
 
M

MikeY

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top