Click here to Skip to main content
15,877,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two buttons called load and new. first you have to read/load the file. when you click new button it must copy the file you loaded/read from load button and overwrite it and shows date modified as well. how can i do that.i tried the code below and nothing happens.

code for copy under new button

FileInfo originalfile = new FileInfo(PathSelection); //this is w
FileInfo newfile = new FileInfo(PathSelection); //i want to
save button
C#
private void btnSave_Click(object sender, EventArgs e)
       {
               saveFileDialog1.InitialDirectory = PathSelection;
               saveFileDialog1.Title = "Save Resource Files";
               saveFileDialog1.CheckPathExists = true;
               saveFileDialog1.DefaultExt = "resx";
               saveFileDialog1.Filter = "Save Resource Files (*.resx)|*.resx";
               saveFileDialog1.RestoreDirectory = true;
               PathSelection = saveFileDialog1.FileName;}
Posted
Comments
Kornfeld Eliyahu Peter 10-Feb-15 7:15am    
https://msdn.microsoft.com/en-us/library/9706cfs5(v=vs.110).aspx

1 solution

Your first issue is that you have not shown the dialog ... you should have something like
C#
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
      PathSelection = saveFileDialog1.FileName;
      //Write to your file here - Filename will contain the fully pathed target
}

The second problem is that the saveDialog doesn't actually save the file for you - you have to do that.

This could be as simple as using File.WriteAllText - it depends on how you've loaded the file under the other button and how you are storing it in memory
 
Share this answer
 
Comments
Bacanzela 10-Feb-15 7:42am    
I am confused with your comment under the code. i have,

here is how i read the file,

oDataSet = new DataSet();
//now am reading the files from the path that is selected
XmlReadMode omode = oDataSet.ReadXml(PathSelection);

for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
{
string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
string font = Between(comment, "[Font]","[/Font]");
string datestamp = Between(comment, "[DateStamp]", "[/DateStamp]");
string commentVal = Between(comment, "[Comment]", "[/Comment]");

string[] row = new string[] { oDataSet.Tables["data"].Rows[i][0].ToString(), oDataSet.Tables["data"].Rows[i][1].ToString(), font, datestamp, commentVal };
Gridview_Input.Rows.Add(row);
CHill60 10-Feb-15 9:03am    
The comment was to indicate where to put your code to save the file - Kornfeld Elihayu Peter gave you one suggestion in the comments - which is probably the best route to copy the existing file, there is another example on the SafeFileDisalog Reference[^] or you can write the Dataset to XML[^]

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