Advertisement

05.15.2007 at 07:19AM PDT, ID: 22573087
[x]
Attachment Details

Help with webservice - uploading to SharePoint doc library with C#

Asked by mwmiller78 in Microsoft Visual C#.Net, C# Programming Language, MOSS-Sharepoint

Tags: sharepoint, upload, library

Here's a webservice I'm having trouble with

<%@ WebService Language="C#" Class="UploadService.Files" %>

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.IO;
using System.Web.Services;

 [WebService(Namespace = "Microsoft.SharePoint.Administration")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Files : System.Web.Services.WebService
    {

        [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.ToLongDateString() + "::" + 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?


TIAStart Free Trial
[+][-]05.15.2007 at 08:53AM PDT, ID: 19093840

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, C# Programming Language, MOSS-Sharepoint
Tags: sharepoint, upload, library
Sign Up Now!
Solution Provided By: mdifranco
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.15.2007 at 09:03AM PDT, ID: 19093935

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.15.2007 at 09:56AM PDT, ID: 19094340

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2007 at 10:02AM PDT, ID: 19094385

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.15.2007 at 10:11AM PDT, ID: 19094457

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2007 at 11:55AM PDT, ID: 19095257

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2007 at 06:31AM PDT, ID: 19100556

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2007 at 08:15AM PDT, ID: 19101475

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32