Note that there are some explanatory texts on larger screens.

plurals
  1. POWebDav 409 Error
    text
    copied!<p>I am trying to add multiple files using WebDav. The directory I am trying to upload to is empty.</p> <p>I loop through the files and sent the files.</p> <p>1 Add doc1.txt to WebDav Server using HTTP Put -- Success always even if the files is already there.</p> <p>2 Add doc2.txt to WebDav Server using HTTP Put -- Always fails with a 409 error.</p> <p>It does not matter what file or order I process the files it always fails on the second file. Anyone have and idea?</p> <p>Here is the method I am using:</p> <pre><code>public static bool UploadFile(string url, string filePath) { if (!File.Exists(filePath)) { return false; } long fileLen = new FileInfo(filePath).Length; HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url); Request.Credentials = mCredentials; Request.Method = WebRequestMethods.Http.Put; Request.ContentLength = fileLen; Request.SendChunked = true; // Specify that overwriting the destination is allowed. Request.Headers.Add(@"Overwrite", @"T"); Request.AllowWriteStreamBuffering = true; System.IO.Stream stream = Request.GetRequestStream(); FileStream fileStrem = new FileStream(filePath, FileMode.Open, FileAccess.Read); int transferRate = 4096; byte[] data = new byte[transferRate]; int read = 0; long totalRead = 0; try { do { read = fileStrem.Read(data, 0, data.Length); if (read &gt; 0) { totalRead += read; stream.Write(data, 0, read); } } while (read &gt; 0); } catch (Exception ex) { throw ex; } finally { stream.Close(); stream.Dispose(); stream = null; fileStrem.Close(); fileStrem.Dispose(); fileStrem = null; } HttpWebResponse Response; try { Response = (HttpWebResponse)Request.GetResponse(); } catch (WebException e) { if (e.Response == null) { Debug.WriteLine("Error accessing Url " + url); throw; } HttpWebResponse errorResponse = (HttpWebResponse)e.Response; //if the file has not been modified if (errorResponse.StatusCode == HttpStatusCode.NotModified) { e.Response.Close(); return false; } else { e.Response.Close(); Debug.WriteLine("Error accessing Url " + url); throw; } } //This case happens if no lastmodedate was specified, but the specified //file does exist on the server. Response.Close(); if (totalRead == fileLen) { return true; } else { return false; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload