Here's a webservice I'm having trouble with
<%@ WebService Language="C#" Class="UploadService.Files
" %>
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebCo
ntrols;
using System.Data;
using System.IO;
using System.Web.Services;
[WebService(Namespace = "Microsoft.SharePoint.Admi
nistration
")]
[WebServiceBinding(Conform
sTo = WsiProfiles.BasicProfile1_
1)]
public class Files : System.Web.Services.WebSer
vice
{
[WebMethod]
public string UploadDocument(string fileName, byte[] fileContents, string pathFolder)
{
if (fileContents == null)
{
return "Null Attachment";
}
try
{
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPFolder folder = web.GetFolder(pathFolder);
string fileURL = fileName;
SPFile file = folder.Files.Add(fileURL, fileContents, true);
return file.TimeCreated.ToLongDat
eString() + "::" + file.Title;
}
catch (System.Exception ex)
{
return ex.Message + "::" + ex.Source;
}
}
}
It uploads files from a network drive to a SharePoint document library. It works great except that it won't overwrite existing files. I have versioning enabled on SharePoint as well. What do I need to do to get it to overwrite?
TIA
Start Free Trial