This is a migrated thread and some comments may be shown as answers.

Default Export Directory

5 Answers 118 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike Matheson
Top achievements
Rank 1
Mike Matheson asked on 10 Sep 2009, 07:52 PM
I'm using the DocumentName to set the default file name for exporting to PDF, but I can't seem to find a way to set the default export folder.  I've tried the code below, but no luck.  Any suggestions?

rpt.DocumentName = string.Format("{2}\\ Quotation {0} for {1}", txtSO.Text, infoVendor.Label,
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory ));

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 11 Sep 2009, 07:32 AM
Hello Mike,

It is not possible to specify default export folder as this is a security vulnerability i.e. this way you would be able to silently copy a file on the client's machine.

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mike Matheson
Top achievements
Rank 1
answered on 11 Sep 2009, 12:49 PM
If I wanted to silently sneek a report onto a users computer, I would use the code below:
    void SaveToFile(Report report, string exportFormat, string reportsLocation)
{
string extension;
string mimeType;
Encoding encoding;

byte[] reportBytes = Telerik.Reporting.Processing.ReportProcessor.Render(exportFormat, report, null, out mimeType, out extension, out encoding);            
string reportName = string.IsNullOrEmpty(report.Name) ? report.GetType().Name : report.Name;
reportName += "." + extension;

using (FileStream fs = new FileStream(reportsLocation + reportName, FileMode.Create))
{
fs.Write(reportBytes, 0, reportBytes.Length);                                                
}            
}


I just want to set the default directory that open in the Save As dailog when the user selects Export PDF from the menu. 
0
Steve
Telerik team
answered on 11 Sep 2009, 03:53 PM
Hi Mike,

You do realize that this would work if you run it on your local machine i.e. the web server is running on your machine. However if you run it on a server and access it from your local machine, you would not be able to do sneak that file on your machine. For the same reasons you cannot use Environment.SpecialFolder.DesktopDirectory, because any server code would be relevant to the server where the app is being run. The Save dialog (in any browser) remembers the last directory used for saving a file and this is machine specific i.e. cannot be controlled from the web application/site.

All the best,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mike Matheson
Top achievements
Rank 1
answered on 11 Sep 2009, 05:07 PM
I guess I should have explained that this is a WinForms application, not a web app.

When the user has the report displayed and picks Export -> Acrobar (PDF) file a Save As dialog appears.  The default directory for this form in My Documents, but I want it to be the desktop so the user can use the file as soon as its exported.
0
Steve
Telerik team
answered on 15 Sep 2009, 03:14 PM
Hi Mike,

Thank you for the clarification. In such case (winforms app), this code should work and it worked fine on our end (see attached video), so please explain what differs on your end and where does the file get saved.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Mike Matheson
Top achievements
Rank 1
Answers by
Steve
Telerik team
Mike Matheson
Top achievements
Rank 1
Share this question
or