Anel
Anel

Reputation: 63

Rendering and saving report file to .pdf

I made app to create reports and save it as .pdf At mine computer after creating report i use this code to save it as .pdf

   Try

        My.Computer.FileSystem.WriteAllBytes("C:\" & Form1.TextBox2.Text & "_Report.pdf", ReportViewer1.LocalReport.Render("pdf"), False)

        MessageBox.Show("Exported to .pdf file on at location C:\", "Note ", MessageBoxButtons.OK, MessageBoxIcon.Information)

    Catch ex As Exception

    End Try

But when i send the application to someone else it won't create this the .pdf on other computer. What is required to be installed ?

Upvotes: 0

Views: 140

Answers (1)

Asamk
Asamk

Reputation: 26

On modern windows computers normal users don't have the permission to access the "C:\" directory directly. When trying to access it with your code, you get a exception, which is in your example code silently ignored.

A better way is to store the file in the users personal folder. You can use the GetFolderPath method to get it:

Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

also see: http://msdn.microsoft.com/de-de/library/system.environment.specialfolder%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb

Upvotes: 1

Related Questions