A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Friday, December 8, 2006

WS Upload Service Demo Using ASP.NET AJAX 1.0 Beta 2

WS Upload Service Demo Using ASP.NET AJAX 1.0 Beta 2
You can download WS UploadService 1.0 from GotDotNet. Here is the download path:
Alternate download location:
You can learn more about this web service in following blog post:
You can call this service in an ajax application. Here is the source code:
<%@ Page Language="C#"%>

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
sp.Files oUploader = new sp.Files();

oUploader.PreAuthenticate = true;
oUploader.Credentials = CredentialCache.DefaultCredentials;

string strPath = txtFilePath.Text;

string strFile = strPath.Substring(strPath.LastIndexOf("\") + 1);

string strDestination = txtDestination.Text;

FileStream fStream = new FileStream(strPath, System.IO.FileMode.Open);
byte[] binFile = new byte[(int)fStream.Length];
fStream.Read(binFile, 0, (int)fStream.Length);

string str = oUploader.UploadDocument(strFile, binFile, strDestination);
lblMessage.Text = "File successfully uploaded.";


void ErrorHandler(object sender, AsyncPostBackErrorEventArgs e)

ScriptManager1.AsyncPostBackErrorMessage = "Error: File could not be uploaded.";


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>WS Upload Service 1.0 - Upload documents remotely to SharePoint</title>

<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="Large"
ForeColor="Blue" Text="WS Upload Service Demo Using ASP.NET AJAX 1.0 Beta 2"></asp:Label><br />
<br />

<asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ErrorHandler" />

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest( endRequest );
function endRequest( sender, e ) {
if( e.get_error() ){
document.getElementById("err").innerText = e.get_error().description;
e.set_errorHandled( true );

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<td style="height: 26px">
<asp:Label ID="lblFilePath" runat="server" Text="Local File Path" Font-Names="Verdana" Font-Size="Small"></asp:Label></td>
<td style="height: 26px">
<asp:TextBox ID="txtFilePath" runat="server" Width=350>C:My DocumentsAjax Techniques.doc</asp:TextBox>
<asp:Label ID="lblDestination" runat="server" Text="Destination Path" Font-Names="Verdana" Font-Size="Small"></asp:Label>
<asp:TextBox ID="txtDestination" runat="server" Width=350>http://sp:17315/Docs</asp:TextBox></td>
<br />

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload File" /><br />
<asp:Label ID="lblMessage" runat="server"></asp:Label>

<br /><br />
<div id="err"></div>
Click here to download the Application (Source code)
Change the web reference before running the application.
Published Friday, December 08, 2006 12:44 AM by


No comments:

Post a Comment