Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an excel file in proprieties ressources and i want to export it using file stream where i can chose the saving path because now it saved at temp and that's not i want

What I have tried:

byte[] myfile = Properties.Resources.canva;
           File.WriteAllBytes(@"c:\temp\canva.xlsx", myfile);
           MessageBox.Show("Canva Loaded Successfully", "Information");
           Process pross = new Process();
           pross.StartInfo.FileName = @"c:\temp\canva.xlsx";
           pross.Start();
Posted
Updated 25-May-20 15:31pm

Quote:
it saved at temp and that's not i want
.. but computers are dumb - that's what you told it to do here
File.WriteAllBytes(@"c:\temp\canva.xlsx", myfile);
you probably need something like
SaveFileDialog savefile = new SaveFileDialog(); 
// set a default file name
savefile.FileName = "canva.xlsx";
// set filters - this can be done in properties as well
savefile.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
savefile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (savefile.ShowDialog() == DialogResult.OK)
{
    File.WriteAllBytes(savefile, myfile);
}


This
Quote:
savefile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
can be set to anywhere appropriate for your application

Does that solve your issue ?
 
Share this answer
 
v2
Comments
Usarsef 25-May-20 21:54pm    
Now the file is in resources i want a button to get it from there to a path using save dialog Hope you understand
Garth J Lancaster 26-May-20 1:10am    
I think I understand that you want everyone to do your work for you. Put a button on your form, look at the button's events, select the ? 'Click(ed) Event, assign a handler to it, then fill out the handler with the code from above.
Maciej Los 26-May-20 2:11am    
5ed!
Seriously? Look at your code and the filepath you are writing the bytes to.

All you have to do is supply a different filepath. That's it!

But, you would have known this had YOU written the code instead of copy'n'paste coding.
 
Share this answer
 
Comments
Usarsef 25-May-20 21:56pm    
I don't need a static path like that @"c:\temp\canva.xlsx", myfile i want the ability to choose the path using save dialog
Dave Kreskowiak 25-May-20 22:34pm    
An SaveFileDialog will give you that. All it does is return a string that represents a filepath. It's really easy to use, as shown in the other answer.

Maciej Los 26-May-20 2:11am    
5ed!

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