Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:06:26+00:00 2026-06-10T21:06:26+00:00

I am facing a problem with WebDav on SharePoint. I made a nice WebDav

  • 0

I am facing a problem with WebDav on SharePoint. I made a nice WebDav library in .NET to support copying and moving files and folder structures, however I cannot get past the following problem.

I’m using .NET 4.0, connecting to SharePoint 2010.

When performing a copy within the same site collection it works fine:

so copy

http://my-sps-server/sc1/folder1/file1.txt

to

http://my-sps-server/sc1/folder2/file1.txt

No problem, but

http://my-sps-server/sc1/folder1/file1.txt

to

http://my-sps-server/sc2/folder2/file1.txt

Throws me an exception and the response status tells me I got a 409 back from the server. Interestingly, before copying I make sure the folder ‘folder2’ exists, if not, it is created, and that works without any problems. But the details of the 409 response tell me the path ‘folder2’ does not exist.

I have been looking into authentication, i’m using the network default credentials, works fine for copying in the same sitecollection and when creating the folder. Also been emulating the http request with fiddler, giving me the same 409 response, so it most likely isn’t the .NET code.

I am wondering if there is anything buggy in SharePoint 2010.

Hope someone can shed a light or hand me some pointers here?

Ended up performing an download from the source and upload to the target (in memory), the code:

    private byte[] DownloadFile(Uri uri)
    {
        var request = GetRequest(uri);
        request.Method = "GET";
        request.Headers.Add("Translate", "f");

        var response = request.GetResponse();

        using (var stream = response.GetResponseStream())
        {
            return ReadFileBytes(stream, (int)response.ContentLength);
        }
    }

    private void UploadFile(Uri uri, byte[] bytes)
    {
        var request = GetRequest(uri);
        request.Method = "PUT";
        request.ContentLength = bytes.Length;
        request.Headers.Add("Translate", "f");

        using (var stream = request.GetRequestStream())
        {
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
        }

        request.GetResponse();
    }

    /// <summary>
    /// Reads data from a stream until the end is reached. The
    /// data is returned as a byte array. An IOException is
    /// thrown if any of the underlying IO calls fail.
    /// </summary>
    /// <param name="stream">The stream to read data from</param>
    /// <param name="initialLength">The initial buffer length</param>
    private static byte[] ReadFileBytes(Stream stream, int initialLength)
    {
        // If we've been passed an unhelpful initial length, just
        // use 32K.
        if (initialLength < 1)
        {
            initialLength = 32768;
        }

        byte[] buffer = new byte[initialLength];
        int read = 0;

        int chunk;
        while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0)
        {
            read += chunk;

            // If we've reached the end of our buffer, check to see if there's
            // any more information
            if (read == buffer.Length)
            {
                int nextByte = stream.ReadByte();

                // End of stream? If so, we're done
                if (nextByte == -1)
                {
                    return buffer;
                }

                // Nope. Resize the buffer, put in the byte we've just
                // read, and continue
                byte[] newBuffer = new byte[buffer.Length * 2];
                Array.Copy(buffer, newBuffer, buffer.Length);
                newBuffer[read] = (byte)nextByte;
                buffer = newBuffer;
                read++;
            }
        }

        // Buffer is now too big. Shrink it.
        byte[] ret = new byte[read];
        Array.Copy(buffer, ret, read);
        return ret;
    }

Take note that downloading and uploading will cost you performance, which could be noticable when doing this with large files.

You can perform the entire copy operation like this:

UploadFile(to, DownloadFile(from));

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:06:27+00:00Added an answer on June 10, 2026 at 9:06 pm

    We recently put a fair amount of time into trying to solve this issue but unfortunately didn’t get anywhere. There’s a number of old StackExchange posts on the subject and the outcome is much the same – nobody really understands what causes this conflict and nobody appears to have properly solved it. What I can tell you which you don’t appear to have found yet is that this often won’t happen if you create new document libraries to move files between and only happens with older ones. This indicates some sort of corruption causes the problem.

    What we did and what may be of use for you is give up and approach this using the SharePoint Object model. The class I wrote for this is below:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    using System.Diagnostics;
    
    // todo: Lists
    // DeleteListItem
    // WriteFileMetadata
    // AddListEntry
    
    // Throttling on copy methods
    
    namespace RE.SharePoint
    {
        /// <summary>
        /// Class to encapsulate methods that interact with SharePoint Lists and Libraries
        /// </summary>
        public class ListsAndItems
        {
            /// <summary>
            /// Move items from a list to another list in the same site
            /// </summary>
            /// <param name="siteURL">URL to the host site collection</param>
            /// <param name="sourceList">URL to the source list</param>
            /// <param name="destinationList">URL to the destination list</param>
            /// <param name="retainMeta">Option to retain meta data (created/modified dates) or create new ones</param>
            /// <returns>Boolean value, true for successful copy, false for a failed copy</returns>
            public bool MoveListItems(string siteURL, string sourceList, string destinationList, bool retainMeta)
            {
                OnSharePointOpeningSite(siteURL);
    
                using (var site = new SPSite(siteURL))
                {
                    OnSharePointOpenedSite(siteURL);
    
                    using (var web = site.OpenWeb())
                    {
                        OnSharePointGetRelativeURL(web.ServerRelativeUrl);
    
                        try
                        {
                            // Get your source and destination libraries
                            var source = web.GetList(web.ServerRelativeUrl + sourceList);
                            var destination = web.GetList(web.ServerRelativeUrl + destinationList);
    
                            OnSharePointSourceSet(source);
                            OnSharePointDestinationSet(destination);
    
                            // Get the collection of items to move, use source.GetItems(SPQuery) if you want a subset
                            SPListItemCollection items = source.Items;
    
                            // Get the root folder of the destination we'll use this to add the files
                            SPFolder folder = web.GetFolder(destination.RootFolder.Url);
    
                            OnSharePointProcessItem(items.Count, source.ToString(), destination.ToString());
    
                            var fileCount = 0;
                            // Now to move the files and the metadata
                            foreach (SPListItem item in items)
                            {
                                //Get the file associated with the item
                                SPFile file = item.File;
    
                                OnSharePointProcessFile(folder.Url + "/" + file.Name);
    
                                // Create a new file in the destination library with the same properties
                                SPFile newFile = folder.Files.Add(folder.Url + "/" + file.Name, file.OpenBinary(), file.Properties, true);
    
                                if (retainMeta)
                                {
                                    SPListItem newItem = newFile.Item;
                                    WriteFileMetaDataFiletoFile(item, newItem);
                                }
    
                                file.Delete();
                                SharePointRecycleBin.EmptyRecycleBinItem(site.ToString(), source.ToString(), file.Name);
    
                                fileCount++;
                            }
    
                            OnSharePointProcessList(fileCount, source.ToString(), destination.ToString());
                        }
                        catch (System.IO.FileNotFoundException fex)
                        {
                            OnError("Unable to set a location. Please check that paths for source and destination libraries are correct and relative to the site collection. \n\nSite URL: " 
                                        + siteURL + " \nSource List: " + sourceList + " \nDestination List: " + destinationList + "\n", false, fex);
    
                            return false;
                        }
                        catch (Exception ex)
                        {
                            OnError("General Exception: ", true, ex);
    
                            return false;
                        }
    
                        return true;
                    }
                }
            }
    
            /// <summary>
            /// Move items from one SharePoint list to another in another site
            /// </summary>
            /// <param name="sourceSiteURL">The URL to the source site collection</param>
            /// <param name="sourceList">The URL to the source list</param>
            /// <param name="destinationSiteURL">The URL to the destination site collection</param>
            /// <param name="destinationList">The URL to the destination list</param>
            /// <param name="retainMeta">Option to retain meta data (created/modified dates) or create new ones</param>
            /// <returns>Boolean value, true for successful copy, false for a failed copy</returns>
            public bool MoveListItemsSiteToSite(string sourceSiteURL, string sourceList, string destinationSiteURL, string destinationList, bool retainMeta)
            {
                OnSharePointOpeningSite(sourceSiteURL);
    
                using (SPSite sourceSite = new SPSite(sourceSiteURL))
                {
                    OnSharePointOpenedSite(sourceSiteURL);
    
                    using (SPWeb sourceWeb = sourceSite.OpenWeb())
                    {
                        OnSharePointGetRelativeURL(sourceWeb.ServerRelativeUrl);
    
                        try
                        {
                            // Get your source library
                            var source = sourceWeb.GetList(sourceWeb.ServerRelativeUrl + sourceList);
    
                            OnSharePointSourceSet(source);
    
                            // Get the collection of items to move, use source.GetItems(SPQuery) if you want a subset
                            SPListItemCollection items = source.Items;
    
                            int fileCount = 0;
    
                            OnSharePointOpeningSite(destinationSiteURL);
    
                            using (var destSite = new SPSite(destinationSiteURL))
                            {
                                OnSharePointOpenedSite(destinationSiteURL);
    
                                using (var destinationWeb = destSite.OpenWeb())
                                {
                                    OnSharePointGetRelativeURL(destinationWeb.ServerRelativeUrl);
    
                                    // get destination library
                                    SPList destination = destinationWeb.GetList(destinationWeb.ServerRelativeUrl + destinationList);
    
                                    OnSharePointDestinationSet(destination);
    
                                    // Get the root folder of the destination we'll use this to add the files
                                    SPFolder destinationFolder = destinationWeb.GetFolder(destination.RootFolder.Url);
    
                                    OnSharePointProcessItem(items.Count, source.ToString(), destination.ToString());
    
                                    // Now to move the files and the metadata
                                    foreach (SPListItem item in items)
                                    {
                                        //Get the file associated with the item
                                        SPFile file = item.File;
    
                                        // Add event handler
                                        OnSharePointProcessFile(destinationFolder.Url + "/" + file.Name);
    
                                        // Create a new file in the destination library with the same properties
                                        SPFile newFile = destinationFolder.Files.Add(destinationFolder.Url + "/" + file.Name, file.OpenBinary(),
                                                                                     file.Properties, true);
    
                                        if (retainMeta)
                                        {
                                            SPListItem newItem = newFile.Item;
                                            WriteFileMetaDataFiletoFile(item, newItem);
                                        }
    
                                        file.Delete();
    
                                        SharePointRecycleBin.EmptyRecycleBinItem(sourceSite.ToString(), source.ToString(), file.Name);
    
                                        fileCount++;
                                    }
                                    OnSharePointProcessList(fileCount, source.ToString(), destination.ToString());
                                }
                            }
                        }
                        catch (System.IO.FileNotFoundException fex)
                        {
                            OnError("Unable to set a location. Please check that paths for source and destination libraries are correct and relative to the site collection. \n\nSource Site: " 
                                        + sourceSiteURL + " \nSource List: " + sourceList + " \nDestination Site: " + destinationSiteURL + " \nDestination List: " + destinationList + "\n", false, fex);
    
                            return false;
                        }
                        catch (Exception ex)
                        {
                            OnError("General Exception: ", true, ex);
    
                            return false;
                        }
    
                        return true;
                    }
                }
            }
    
            /// <summary>
            /// overwrites a list items meta data with meta data from another file
            /// </summary>
            /// <param name="sourceItem">The source item to take meta data from</param>
            /// <param name="destinationItem">The destination item to set meta data from the source item to</param>
            public static void WriteFileMetaDataFiletoFile(SPListItem sourceItem, SPListItem destinationItem)
            {
                destinationItem["Editor"] = sourceItem["Editor"];
                destinationItem["Modified"] = sourceItem["Modified"];
                destinationItem["Modified By"] = sourceItem["Modified By"];
                destinationItem["Author"] = sourceItem["Author"];
                destinationItem["Created"] = sourceItem["Created"];
                destinationItem["Created By"] = sourceItem["Created By"];
    
                destinationItem.UpdateOverwriteVersion();
            }
    
    
            #region Events
    
            internal void OnSharePointProcessFile(string itemPath)
            {           
                if (_sharePointProcessedFile == null) return;
    
                var e = new SharePointProcessFileEventArgs(itemPath);
                _sharePointProcessedFile(this, e);
            }
    
            internal void OnSharePointProcessItem(int itemCount, string source, string destination)
            {
                if (_sharePointProcessItem == null) return;
    
                var e = new SharePointProcessItemEventArgs(itemCount, source, destination);
    
                _sharePointProcessItem(this, e);
            }
    
    
            internal void OnSharePointProcessList(int itemCount, string source, string destination)
            {
                if (_sharePointProcessList == null) return;
    
                var e = new SharePointProcessListEventArgs(itemCount, source, destination);
    
                _sharePointProcessList(this, e);
            }
    
    
            internal void OnSharePointOpeningSite(string siteName)
            {
                if (_sharePointOpeningSite == null) return;
    
                var e = new SharePointOpeningSiteEventArgs(siteName);
    
                _sharePointOpeningSite(this, e);
            }
    
            internal void OnSharePointOpenedSite(string siteName)
            {
                if (_sharePointOpenedSite == null) return;
    
                var e = new SharePointOpenedSiteEventArgs(siteName);
    
                _sharePointOpenedSite(this, e);
            }
    
            internal void OnSharePointGetRelativeURL(string siteCollection)
            {
                if (_sharePointRelativeURL == null) return;
    
                var e = new SharePointWebRelativeURLEventArgs(siteCollection);
    
                _sharePointRelativeURL(this, e);
            }
    
            internal void OnSharePointDestinationSet(SPList destination)
            {
                if (_sharepointDestination == null) return;
    
                var e = new SharePointDestinationSetEventArgs(destination);
    
                _sharepointDestination(this, e);
            }
    
            internal void OnSharePointSourceSet(SPList source)
            {
                if (_sharepointSource == null) return;
    
                var e = new SharePointSourceSetEventArgs(source);
    
                _sharepointSource(this, e);
            }
    
            internal void OnError(string message, bool showException, Exception exception)
            {
                if (_sharePointOnError == null) return;
    
                var e = new SharePointOnErrorEventsArgs(message, showException, exception);
    
                _sharePointOnError(this, e);
            }
    
            private EventHandler<SharePointProcessFileEventArgs> _sharePointProcessedFile;
            private EventHandler<SharePointProcessListEventArgs> _sharePointProcessList;
            private EventHandler<SharePointOpeningSiteEventArgs> _sharePointOpeningSite;
            private EventHandler<SharePointOpenedSiteEventArgs> _sharePointOpenedSite;
            private EventHandler<SharePointWebRelativeURLEventArgs> _sharePointRelativeURL;
            private EventHandler<SharePointDestinationSetEventArgs> _sharepointDestination;
            private EventHandler<SharePointSourceSetEventArgs> _sharepointSource;
            private EventHandler<SharePointProcessItemEventArgs> _sharePointProcessItem;
            private EventHandler<SharePointOnErrorEventsArgs> _sharePointOnError;
    
            /// <summary>
            /// Event for handling exceptions
            /// </summary>
            public event EventHandler<SharePointOnErrorEventsArgs> SharePointOnError
            {
                add { _sharePointOnError += value; }
                remove { _sharePointOnError += value; }
            }
    
            /// <summary>
            /// Event for when a file is being processed
            /// </summary>
            public event EventHandler<SharePointProcessFileEventArgs> SharePointProcessFile
            {
                add { _sharePointProcessedFile += value; }
                remove { _sharePointProcessedFile += value; }
            }
    
            /// <summary>
            /// Event for when a site is attempting to open
            /// </summary>
            public event EventHandler<SharePointOpeningSiteEventArgs> SharePointOpeningSite
            {
                add { _sharePointOpeningSite += value; }
                remove { _sharePointOpeningSite -= value; }
            }
    
            /// <summary>
            /// Event for when a site has been successfully opened
            /// </summary>
            public event EventHandler<SharePointOpenedSiteEventArgs> SharePointOpenedSite
            {
                add { _sharePointOpenedSite += value; }
                remove { _sharePointOpenedSite -= value; }
            }
    
            /// <summary>
            /// Event for when source/destination and filecount are established and a copy is about to initiate
            /// </summary>
            public event EventHandler<SharePointProcessItemEventArgs> SharePointProcessItem
            {
                add { _sharePointProcessItem += value; }
                remove { _sharePointProcessItem -= value; }
            }
    
            /// <summary>
            /// Event for when a list has started processing
            /// </summary>
            public event EventHandler<SharePointProcessListEventArgs> SharePointProcessList
            {
                add { _sharePointProcessList += value; }
                remove { _sharePointProcessList -= value; }
            }
    
            /// <summary>
            /// Event for when a web relative URL has been retreived from the site collection name
            /// </summary>
            public event EventHandler<SharePointWebRelativeURLEventArgs> SharePointWebRelativeURL
            {
                add { _sharePointRelativeURL += value; }
                remove { _sharePointRelativeURL -= value; }
            }
    
            /// <summary>
            /// Event for when a destination location has been assigned
            /// </summary>
            public event EventHandler<SharePointDestinationSetEventArgs> SharePointDestinationSet
            {
                add { _sharepointDestination += value; }
                remove { _sharepointDestination -= value; }
            }
    
            /// <summary>
            /// Event for when a source location has been assigned
            /// </summary>
            public event EventHandler<SharePointSourceSetEventArgs> SharePointSourceSet
            {
                add { _sharepointSource += value; }
                remove { _sharepointSource -= value; }
            }
    
        #endregion 
        }
    }
    

    I’ll also bounty this post for you once that option is available… Hopefully enough time has now passed so that somebody in the community knows how to solve this problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing problem with an Oracle Query in a .net 2.0 based windows
I am facing problem while setting the backGround Image of LinearLayout from asset folder.
Iam facing problem in understanding and converting a matlab code into opencv. I want
iam facing problem in passing array to view. this is my controller code.. function
I am facing problem while setting focus in EdiText. Below is my EditText property.
I am facing problem of duplicate rows in the JXTable . If I sort
I am facing problem in intercepting and changing request url to link it with
I am facing problem with iframe that too in chrome. How to make IFRAME
I am facing problem to get variable from query string. I have used htaccess
I am facing problem with UIPanGestureRecognizer. suppose i am adding 10 button dynamicaly using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.