Download Documents with javascript object model RRS feed

  • Question

  • I'd like to use the javascript client object model to get a document from a document library and upload it to a WCF Restful web services. This looks straight forward in Silverlight but I can't find anything in JS. Ideally I'd like to:

    Call the document library via Rest so I can use JQuery. However when I look at the document library metadata there is nothing for the document itself.
    Use the object model but I can't see anything on getting the actual document.

    If I can get the document what format will it be in? Base64 string? So I know how to handle it in my web service.

    Cheers, Chris.


    Saturday, February 25, 2012 3:42 PM


  • I never used JS to get the content of document in the document library, but I ever did this by C# code. I think it's easy to translate it into a web service, then use your JS to communicate with this service.

    SPFolder srcFolder = SpWeb.Folders[LibName];
    SPFile srcFile = srcFolder.Files[ItemName];
    UTF8Encoding encoding = new UTF8Encoding();
    String templateContent = encoding.GetString(srcFile.OpenBinary());

    Hope it helps

    Regards, Nighting Liu

    • Marked as answer by Shimin Huang Tuesday, March 6, 2012 6:50 AM
    Saturday, February 25, 2012 4:19 PM