I have a template/format in excel which has to be used to generate salary slips. I have saved it in a document library and using interop, open an instance of it in a workbook programmatically. After I populate it with elements I retrieve from a list, I have to save it as a file in another document library. How do I do it?

I am trying to implement it in an autohosted app.

  • Are you using sharepoint online or sharepoint foundation 2010? – Aanchal May 28 '14 at 7:37
  • I am using cloud version of sharepoint – Swayam Siddha May 28 '14 at 9:53
  • I am able to open an excel file stored in a library, am able to modify it. I want to store the file in another library. – Swayam Siddha May 28 '14 at 9:58

As far as i understand your question, After doing modification you can upload the file to sharepoint using CSOM.

 ClientContext context = new ClientContext("http://spdevinwin");

 Web web = context.Web;

   FileCreationInformation newFile = new FileCreationInformation();
 newFile.Content = System.IO.File.ReadAllBytes(@"C:\Work\Files\17580_FAST2010_S05_Administration.pptx");
  newFile.Url = "17580_FAST2010_S05_Administration 4MB file uploaded via client OM.pptx";

    List docs = web.Lists.GetByTitle("Documents");
 Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);

so you can set newFile.Content with your files byte array.

Please correct me if i am not able to understand you.

|improve this answer|||||
  • I am using this for an autohosted app for the cloud version of sharepoint. I am not sure if this would work for cloud! – Swayam Siddha May 28 '14 at 9:56
  • You can try this as this is client object model. But just remember to create credentials as SecureString passWord = new SecureString(); foreach (char c in "yourpassword".ToCharArray()) passWord.AppendChar(c); clientContext.Credentials = new SharePointOnlineCredentials("loginname@yoursite.onmicrosoft.com", passWord); – Aanchal May 28 '14 at 10:03
  • I know that, but whats the location of the edited file in sharepoint cloud. As I said, i've opened a file in a document library and edited it. What param should I give to ReadAllBytes? My source is a worksheet object. I dont have the location of this object!! – Swayam Siddha May 28 '14 at 10:14
  • So what you can do is download the file first then upload that file to other location. Is there any problem with this approach? – Aanchal May 28 '14 at 10:22
  • Also you should use provider hosted apps as Microsoft discontinues Autohosted Apps model in SharePoint Online.thuansoldier.net/?p=4058 – Aanchal May 28 '14 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.