pdfDoc.Save() Filename should not contain path

Hi…

What am I doing wrong? I am trying to create and open a pdf document and keep getting the following error:

Filename should not contain path.

Here is the code:


string strFileName = @"\servername\c$\temp\test.pdf";
try {
this.pdfDocument.Save(strFileName, Aspose.Pdf.SaveType.OpenInAcrobat, this.Response);
}
catch (Exception ex) {
this.Label8.Text = ex.Message;
}

I have tried combinations of file names, leaving out the path etc and nothing works. I want the client (browser) end user to be able to veiw the document created by the web server.

Just reading through the other forum entries, if I take the path away I get the same result as:

Word to PDF - OpenInBrowser/OpenInAcrobat

Please help!

Dear APDEV,

Thank you for considering Aspose.

"\servername…" is not supported in Pdf.Save method. Please map a network disk if you want to save the document into another server.

Thanks for your response Tommy.

The only reason that I used \\servername\ was that my previous attempts to specify just a file name i.e. test.pdf has not worked. My thinking was that setting the complete file path to the full UNC path would enable the client to pick up the document. Ok, so this is not corrent, should my initial attempt have worked?

My initial attempt:

string strFileName = "test.pdf";
try {
this.pdfDocument.Save(strFileName, Aspose.Pdf.SaveType.OpenInAcrobat, this.Response);
}
catch (Exception ex) {
this.Label8.Text = ex.Message;
}

The error I get:

There was an error opening this document. The file is damaged and could not be repaired.

This is regardless if I "save to disk" or "open from the orig location".

Hi APDEV,

Someone else reported this error too. But I have failed to reproduce this error. Can you please send me a complete exampe that can reproduce this error?

Please also tell me which area are you in and which language you are using. This error maybe relating to the CultureInfo.

The code is based on one of the examples in Aspose documentation. I had planned to get it working and then to start customisation. It is on a Windows 2003 Server with .NET framework 1.1 SP1..

Report code is as follows:

protected Pdf pdfDocument = null;
protected Section pdfSection = null;

private void createDocument() {
Response.Write("createDocument()");
this.pdfDocument = new Pdf();
this.pdfSection = this.pdfDocument.Sections.Add();
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
this.pdfSection.Paragraphs.Add(tab1);
tab1.ColumnWidths = "50 50 50";
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All,0.1F);
tab1.Border = new BorderInfo((int)BorderSide.All,1F);
Row row1 = tab1.Rows.Add();
row1.Cells.Add("col1");
row1.Cells.Add("col2");
row1.Cells.Add("col3");
Row row2 = tab1.Rows.Add();
row2.Cells.Add("item1");
row2.Cells.Add("item2");
row2.Cells.Add("item3");
}

private void saveDocument() {
string strFileName = "test.pdf";
try {
this.pdfDocument.Save(strFileName, Aspose.Pdf.SaveType.OpenInAcrobat, this.Response);
}
catch (Exception ex) {
this.Label8.Text = ex.Message;
}
}

private void btnGenerate_Click(object sender, System.EventArgs e) {
Response.Write("btnGenerate_Click()");
scDbConnection = this.getNewDbConnection();
if (scDbConnection != null) {
this.createDocument();

this.saveDocument();
}
}

Seems the solution in thread “Word to PDF - OpenInBrowser/OpenInAcrobat” fixed my problem also.

Why is this line required?

Dear APDEV,

Thank you for considering Aspose.

I am very glad to here that. Response.End() is needed by Asp.Net, I think.