Using SharePoint WebService to upload a document from .net web application
<asp:FileUpload ID=”File1″ runat=”server” />
<asp:Button ID=”Button1″ runat=”server”
Text=”Button” onclick=”Button1_Click” />
protected void Button1_Click(object sender, EventArgs e)
{
CopyServiceToSharePoint.Copy copyService = new CopyServiceToSharePoint.Copy();
copyService.Url = "http://SERVER/sites/YOURSITE/_vti_bin/copy.asmx";
copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;
if (File1.PostedFile == null)
return;
Stream fStream = File1.PostedFile.InputStream;
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
string sourceUrl = File1.PostedFile.FileName.ToString();
string filename = System.IO.Path.GetFileName(sourceUrl);
string[] destinationURL = { “http://SERVER/sites/YOURSITE/Shared%20Documents/” + filename };
CopyServiceToSharePoint.CopyResult cResult1 = new CopyServiceToSharePoint.CopyResult();
CopyServiceToSharePoint.CopyResult cResult2 = new CopyServiceToSharePoint.CopyResult();
CopyServiceToSharePoint.CopyResult[] cResultArray = { cResult1, cResult2 };
CopyServiceToSharePoint.FieldInformation fFiledInfo = new CopyServiceToSharePoint.FieldInformation();
fFiledInfo.DisplayName = “Description”;
fFiledInfo.Type = CopyServiceToSharePoint.FieldType.Text;
fFiledInfo.Value = “Sample Description”;
CopyServiceToSharePoint.FieldInformation[] fFiledInfoArray = { fFiledInfo };
uint copyresult = copyService.CopyIntoItems(sourceUrl, destinationURL, fFiledInfoArray, contents, out cResultArray);
}