I have created a SLDocument, in which I have saved what I have obtained from an XML, but I want the user to save it in the location user wants, I have seen that the SLDocument only has the SaveAs option and I must specify the route, so I do not know how I can make the "save in" dialog show, can someone help me please?
Asked
Active
Viewed 402 times
1 Answers
1
You can use the built-in Windows dialog, using something like this:
var dialog = new Microsoft.Win32.SaveFileDialog
{
FileName = "defaultfilename.jpg",
DefaultExt = ".jpg",
};
bool? result = dialog.ShowDialog(); // true if the user saved, false if they cancelled
string filepath = dialog.FileName;

Scott Caldwell
- 121
- 4
-
1@AlexZ Just to add on to this... Pass in `filepath` to `SLDocument.SaveAs Method(String)` – fourwhey Sep 11 '18 at 17:40
-
I try with SaveFileDialog but i have this error "El subproceso actual debe establecerse en el modo de subprocesamiento controlado simple (Single Thread Apartment, STA) para poder realizar llamadas OLE. Asegúrese de que la función Main tiene marcado STAThreadAttribute. Esta excepción sólo se desencadena si se adjunta un depurador al proceso." i haven´t main in my class – AlexZ Sep 11 '18 at 18:56
-
Are you using Windows Forms or WPF? – Scott Caldwell Sep 11 '18 at 19:31
-
@AlexZ Even if it is WinForms that error can still occur if it's being invoked from something other than the UI thread. Read this if you are using WinForms. https://www.codeproject.com/Articles/841702/Thread-Apartment-Safe-Open-Save-File-Dialogs-for-C – fourwhey Sep 11 '18 at 20:13
-
Also i try with response but file only contain name sldocument, i try with this Response.Clear(); Response.ContentType = "application/xls"; Response.AddHeader("content-disposition", "attachment;filename=ExcelDocument_" + DateTime.Now.ToString("ddMMyyyy_HMs") + ".xls"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(slExcel); Response.End(); – AlexZ Sep 11 '18 at 20:52