Monday, 15 August 2011

c# - Saving website as document in SharePoint 2013 -



c# - Saving website as document in SharePoint 2013 -

i generate page (html) dynamically within application page.

now need archive page within document library. pdf great, word ok. html worst case.

if needed alter html aspx of course.

while found lot of pages explaining sp2013s new pdf-features end users did not find illustration how code without using third-party tools.

you can utilize new syncconverter class introduced in sharepoint 2013 part of word automation services. able utilize need include microsoft.office.word.server.dll located in c:\program files\common files\microsoft shared\web server extensions\15\isapi folder.

using microsoft.office.word.server.conversions; var filecontent = "<html><body><h1> blah blah blah </h1></body></html>"; using (var read = generatestreamfromstring(filecontent)) using (var write = new memorystream()) using (var site = new spsite("http://localhost")) using (var web = site.openweb()) { var wordautomationservicename = "word automation services"; var sc = new syncconverter(wordautomationservicename); sc.usertoken = site.usertoken; sc.settings.updatefields = true; sc.settings.outputformat = saveformat.pdf; var info = sc.convert(read, write); if (info.succeeded) { var folder = web.lists["documents"].rootfolder; folder.files.add("http://localhost/documents/syncconverted.pdf", write); } } public static stream generatestreamfromstring(string s) { var stream = new memorystream(); var author = new streamwriter(stream); writer.write(s); writer.flush(); stream.position = 0; homecoming stream; }

c# pdf sharepoint sharepoint-2013

No comments:

Post a Comment