locked
Programmatically upload xlsx to sharepoint document library RRS feed

  • Question

  • How can I programmatically upload an xlsx document to a sharepoint document library?
    I know how to upload a xls document but it causing an error when using an office 2007 xlsx document.
    • Edited by M Roy Thursday, November 6, 2008 5:30 PM
    Thursday, November 6, 2008 5:29 PM

Answers

  •  Thanks. I got it figured out.
    • Edited by M Roy Friday, November 7, 2008 5:09 PM
    • Marked as answer by M Roy Friday, November 7, 2008 5:10 PM
    Thursday, November 6, 2008 10:16 PM

All replies

  • You will be able to upload the xlsx documents through the list web services or the SP objects.


    Ameet Phadnis (e Tek Global Inc.)
    Thursday, November 6, 2008 6:53 PM
  • You can use the copy.asmx web service as follows:

      public static void CreateNewDocumentWithCopyService(string fileName)  
            {  
     
     
                copyservice.Copy c = new copyservice.Copy();  
                c.Url = "http://basesmcdev2/sites/tester1/_vti_bin/copy.asmx";  
                c.UseDefaultCredentials = true;  
     
                byte[] myBinary = File.ReadAllBytes(fileName);  
                string destination = "http://basesmcdev2/sites/tester1/tester2/" + fileName;  
                string[] destinationUrl = { destination };  
     
                copyservice.FieldInformation info1 = new copyservice.FieldInformation();  
                info1.DisplayName = "Title";  
                info1.InternalName = "Title";  
                info1.Type = copyservice.FieldType.Text;  
                info1.Value = "whateverForMe";  
     
                copyservice.FieldInformation[] info = { info1};  
                copyservice.CopyResult resultTest = new copyservice.CopyResult();  
                copyservice.CopyResult[] result = { resultTest };  
     
                try  
                {  
                    //You use same URL in the SourceURI as in the Destination URL  
                    c.CopyIntoItems(destination, destinationUrl, info, myBinary, out result);  
                }  
                catch (Exception ex)  
                {  
     
                }  
     
     
     
            } 

    http://www.certdev.com
    Thursday, November 6, 2008 7:07 PM
  •  Thanks. I got it figured out.
    • Edited by M Roy Friday, November 7, 2008 5:09 PM
    • Marked as answer by M Roy Friday, November 7, 2008 5:10 PM
    Thursday, November 6, 2008 10:16 PM