Sunday, November 24, 2013

Javascript to upload a file to SharePoint 2010 document library

Thanks Kelly. I tried the first method and I am getting object expected error in the first line. Below is the code. Please let me know if I am missing anything.


<input id="uploadDocumentButton" onclick="UploadDocument()" type="button" value="Upload Document"/><script type="text/C#" runat="server">


public Boolean UploadDocument()

{


ClientContext ctx = new ClientContext("mysharepoint URL");


Web currentWeb = ctx.Web;


ctx.Load(currentWeb);


ctx.ExecuteQuery();


using (FileStream fs = new FileStream("C:\KPP.txt", FileMode.Open))

{

Microsoft.SharePoint.Client.File.SaveBinaryDirect(ctx, "/JSOM%20Documents/"+ "KPP.txt", fs, true);

}


Console.WriteLine("Uploaded File Successfully");


}</script>


No comments:

Post a Comment