I have a excel file stream which needs to be saved in a pdf format. I am getting an error trying to do that...If you could help, I would really appreciate it.
SPSite/SpWeb ==> objects are SharePoint objects which helps to open an excel file from a url location and put it in a stream.
using (SPSite spSite = new SPSite(documentUrl))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
try
{
SPFile spFile = spWeb.GetFile(documentUrl);
using (Stream stream = spFile.OpenBinaryStream())
{
Workbook workBook = new Workbook();
workBook.Save(stream, FileFormatType.AsposePdf);
//workBook.Save(stream, FileFormatType.SpreadsheetML);
Pdf pdf = new Pdf();
pdf.BindXML(stream, null);
/// Upload the file
spWeb.GetFile(destinationUrl).Delete(); //Delete file if incase exists
byte[] contents = pdf.GetBuffer();
spWeb.Files.Add(destinationUrl, contents);
}
}
catch (Exception ex)
{
string error = ex.Message;
}
}
}