In Sharepoint 2013 library Name "A", there are more then 1000 PPTX (Powerpoint) Files within that , I have to convert all these to PDF file. I have used Power Point Automation service for convert those item. But i can only convert 1 Items and store it in Library "B", I wanted to Convert all PPTX items to PDF and store it in Library "B". Below is the Code I have Used, Please help me.
namespace PptxToPdfConversion
{
class Program
{
static void Main(string[] args)
{
try
{
string siteURL = "My Site URL ";
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
Console.WriteLine("Begin conversion");
SPFolder docs = web.Folders[siteURL +
"/List Name A"];
SPFile file = docs.Files[siteURL +
"/Presentations/Test.pptx"];
Stream fStream = file.OpenBinaryStream();
SPFileStream stream = new SPFileStream(web, 0x1000);
// Create the presentation conversion request.
PresentationRequest request = new PresentationRequest(
fStream,
".pptx",
stream);
IAsyncResult result = request.BeginConvert(
SPServiceContext.GetContext(site),
null,
null);
request.EndConvert(result);
// Add the converted file to the document library.
SPFolder PDFdocs = web.Folders[siteURL +
"/List B"];
SPFile newFile = PDFdocs.Files.Add(
"Text.pdf",
stream,
true);
Console.WriteLine("Output: {0}", newFile.Url);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
finally
{
Console.WriteLine("Complete");
Console.ReadKey();
}
}
}
}