473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Programmatically uploading a file via WebDAV using HttpWebRequest/FileWebRequest

I'm trying to build a routine that will take a specified file from the
user's local hard drive, and copy it to a remote server via WebDAV. I've
tried using both HttpWebRequest and FileWebRequest, as outlined in some
samples I found on MSDN and elsewhere, but so far have had no luck
whatsoever. The copy process doesn't fail, but neither does the targeted
file actually appear on the destination server. I have verified that I can
copy files manually to the target WebDAV folder, via a mapped network
resource on Windows XP. Word XP successfully loads and saves files to the
target folder as well.

Here's the code I'm using:

Dim MyResponse As HttpWebResponse
Dim MyCredentialCache = New System.Net.CredentialCache
Dim UserName As String = "MyUserName"
Dim Password As String = "MyPassword"
Dim Domain As String = "MyDomain"
Dim SourceURI As String = "http://localhost/text.xml"
Dim MyRequest As HttpWebRequest = CType(WebRequest.Create(SourceURI),
HttpWebRequest)

Try

MyCredentialCache.Add(New System.Uri(SourceURI), "NTLM", New
System.Net.NetworkCredential(UserName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Credentials = MyCredentialCache
MyRequest.Headers.Add("Destination",
"http://DestinationServer/SubFolder/text.xml")
MyRequest.Headers.Add("Overwrite", "F")
MyRequest.Method = "COPY"
MyResponse = CType(MyRequest.GetResponse(), HttpWebResponse)
MyResponse.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The status code contained in the response object will say "Created" every
time, but no actual file appears. I have also used a slightly modified
version of this code that uses FileWebRequest instead of HttpWebRequest,
with similar results. Essentially, in that case, the response object
contains a stream that appears to have all the data from the source file in
it, but the file itself never appears in the target folder. Any insight
would be greatly appreciated!

Thanks,

Shannon
Nov 20 '05 #1
4 15372
I'm not sure, bu I think you must also stream the data up to the server. But that's just a guess.
If you're not sure what's happening behind the doors then I'd try a packet sniffer and monitor the actual request going out - there
you should see if your file data actually makes it over the wire. Try www.ethereal.com for a nice freeware packet capture.

-markus
"Shannon Hardin" <sh*****@alginc.com> wrote in message news:un**************@TK2MSFTNGP10.phx.gbl...
I'm trying to build a routine that will take a specified file from the
user's local hard drive, and copy it to a remote server via WebDAV. I've
tried using both HttpWebRequest and FileWebRequest, as outlined in some
samples I found on MSDN and elsewhere, but so far have had no luck
whatsoever. The copy process doesn't fail, but neither does the targeted
file actually appear on the destination server. I have verified that I can
copy files manually to the target WebDAV folder, via a mapped network
resource on Windows XP. Word XP successfully loads and saves files to the
target folder as well.

Here's the code I'm using:

Dim MyResponse As HttpWebResponse
Dim MyCredentialCache = New System.Net.CredentialCache
Dim UserName As String = "MyUserName"
Dim Password As String = "MyPassword"
Dim Domain As String = "MyDomain"
Dim SourceURI As String = "http://localhost/text.xml"
Dim MyRequest As HttpWebRequest = CType(WebRequest.Create(SourceURI),
HttpWebRequest)

Try

MyCredentialCache.Add(New System.Uri(SourceURI), "NTLM", New
System.Net.NetworkCredential(UserName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Credentials = MyCredentialCache
MyRequest.Headers.Add("Destination",
"http://DestinationServer/SubFolder/text.xml")
MyRequest.Headers.Add("Overwrite", "F")
MyRequest.Method = "COPY"
MyResponse = CType(MyRequest.GetResponse(), HttpWebResponse)
MyResponse.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The status code contained in the response object will say "Created" every
time, but no actual file appears. I have also used a slightly modified
version of this code that uses FileWebRequest instead of HttpWebRequest,
with similar results. Essentially, in that case, the response object
contains a stream that appears to have all the data from the source file in
it, but the file itself never appears in the target folder. Any insight
would be greatly appreciated!

Thanks,

Shannon

Nov 20 '05 #2
Markus,

I found the solution, and you are correct. It is the responsibility of the
client to also stream the data to the server. Unfortunately, Microsoft's
own article and sample code fail to mention this small fact, for some
reason.

I actually found an even simpler way to do these types of copy. ADO with
the Internet Publishing provider can handle it, and that's the method I
went with.

Thanks,

Shannon

"Markus Hahn" <ma*********@gmx.net> wrote in message
news:3R****************@newsread1.news.pas.earthli nk.net...
I'm not sure, bu I think you must also stream the data up to the server. But that's just a guess. If you're not sure what's happening behind the doors then I'd try a packet sniffer and monitor the actual request going out - there you should see if your file data actually makes it over the wire. Try www.ethereal.com for a nice freeware packet capture.
-markus
"Shannon Hardin" <sh*****@alginc.com> wrote in message

news:un**************@TK2MSFTNGP10.phx.gbl...
I'm trying to build a routine that will take a specified file from the
user's local hard drive, and copy it to a remote server via WebDAV. I've tried using both HttpWebRequest and FileWebRequest, as outlined in some
samples I found on MSDN and elsewhere, but so far have had no luck
whatsoever. The copy process doesn't fail, but neither does the targeted file actually appear on the destination server. I have verified that I can copy files manually to the target WebDAV folder, via a mapped network
resource on Windows XP. Word XP successfully loads and saves files to the target folder as well.

Here's the code I'm using:

Dim MyResponse As HttpWebResponse
Dim MyCredentialCache = New System.Net.CredentialCache
Dim UserName As String = "MyUserName"
Dim Password As String = "MyPassword"
Dim Domain As String = "MyDomain"
Dim SourceURI As String = "http://localhost/text.xml"
Dim MyRequest As HttpWebRequest = CType(WebRequest.Create(SourceURI), HttpWebRequest)

Try

MyCredentialCache.Add(New System.Uri(SourceURI), "NTLM", New
System.Net.NetworkCredential(UserName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Credentials = MyCredentialCache
MyRequest.Headers.Add("Destination",
"http://DestinationServer/SubFolder/text.xml")
MyRequest.Headers.Add("Overwrite", "F")
MyRequest.Method = "COPY"
MyResponse = CType(MyRequest.GetResponse(), HttpWebResponse)
MyResponse.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The status code contained in the response object will say "Created" every time, but no actual file appears. I have also used a slightly modified
version of this code that uses FileWebRequest instead of HttpWebRequest,
with similar results. Essentially, in that case, the response object
contains a stream that appears to have all the data from the source file in it, but the file itself never appears in the target folder. Any insight
would be greatly appreciated!

Thanks,

Shannon


Nov 20 '05 #3

Hello Shannon,

I have been trying to do the same thing and I am getting
the same error.
Can u help me with eth esolution u have found.

Thanks in advance.

Regards,
Santosh

Shannon Hardin wrote:
*I'm trying to build a routine that will take a specified file fro
the
user's local hard drive, and copy it to a remote server via WebDAV.
I've
tried using both HttpWebRequest and FileWebRequest, as outlined i
some
samples I found on MSDN and elsewhere, but so far have had no luck
whatsoever. The copy process doesn't fail, but neither does th
targeted
file actually appear on the destination server. I have verified tha
I can
copy files manually to the target WebDAV folder, via a mappe
network
resource on Windows XP. Word XP successfully loads and saves file
to the
target folder as well.

Here's the code I'm using:

Dim MyResponse As HttpWebResponse
Dim MyCredentialCache = New System.Net.CredentialCache
Dim UserName As String = "MyUserName"
Dim Password As String = "MyPassword"
Dim Domain As String = "MyDomain"
Dim SourceURI As String = "http://localhost/text.xml"
Dim MyRequest As HttpWebRequest
CType(WebRequest.Create(SourceURI),
HttpWebRequest)

Try

MyCredentialCache.Add(New System.Uri(SourceURI), "NTLM", New
System.Net.NetworkCredential(UserName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Credentials = MyCredentialCache
MyRequest.Headers.Add("Destination",
"http://DestinationServer/SubFolder/text.xml")
MyRequest.Headers.Add("Overwrite", "F")
MyRequest.Method = "COPY"
MyResponse = CType(MyRequest.GetResponse(), HttpWebResponse)
MyResponse.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The status code contained in the response object will say "Created
every
time, but no actual file appears. I have also used a slightl
modified
version of this code that uses FileWebRequest instead o
HttpWebRequest,
with similar results. Essentially, in that case, the respons
object
contains a stream that appears to have all the data from the sourc
file in
it, but the file itself never appears in the target folder. An
insight
would be greatly appreciated!

Thanks,

Shannon

-
santoshpotda
-----------------------------------------------------------------------
Posted via http://www.mcse.m
-----------------------------------------------------------------------
View this thread: http://www.mcse.ms/message342150.htm

Nov 21 '05 #4
Here is the method I used and it works well.

http://support.microsoft.com/default...b;en-us;323245
"santoshpotdar" <sa******************@mail.mcse.ms> wrote in message
news:sa******************@mail.mcse.ms...

Hello Shannon,

I have been trying to do the same thing and I am getting
the same error.
Can u help me with eth esolution u have found.

Thanks in advance.

Regards,
Santosh

Shannon Hardin wrote:
*I'm trying to build a routine that will take a specified file from
the
user's local hard drive, and copy it to a remote server via WebDAV.
I've
tried using both HttpWebRequest and FileWebRequest, as outlined in
some
samples I found on MSDN and elsewhere, but so far have had no luck
whatsoever. The copy process doesn't fail, but neither does the
targeted
file actually appear on the destination server. I have verified that
I can
copy files manually to the target WebDAV folder, via a mapped
network
resource on Windows XP. Word XP successfully loads and saves files
to the
target folder as well.

Here's the code I'm using:

Dim MyResponse As HttpWebResponse
Dim MyCredentialCache = New System.Net.CredentialCache
Dim UserName As String = "MyUserName"
Dim Password As String = "MyPassword"
Dim Domain As String = "MyDomain"
Dim SourceURI As String = "http://localhost/text.xml"
Dim MyRequest As HttpWebRequest =
CType(WebRequest.Create(SourceURI),
HttpWebRequest)

Try

MyCredentialCache.Add(New System.Uri(SourceURI), "NTLM", New
System.Net.NetworkCredential(UserName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Credentials = MyCredentialCache
MyRequest.Headers.Add("Destination",
"http://DestinationServer/SubFolder/text.xml")
MyRequest.Headers.Add("Overwrite", "F")
MyRequest.Method = "COPY"
MyResponse = CType(MyRequest.GetResponse(), HttpWebResponse)
MyResponse.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

The status code contained in the response object will say "Created"
every
time, but no actual file appears. I have also used a slightly
modified
version of this code that uses FileWebRequest instead of
HttpWebRequest,
with similar results. Essentially, in that case, the response
object
contains a stream that appears to have all the data from the source
file in
it, but the file itself never appears in the target folder. Any
insight
would be greatly appreciated!

Thanks,

Shannon *


--
santoshpotdar
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message342150.html

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rbt | last post by:
Has anyone used pure python to upload files to a webdav server over SSL? I have no control over the server. I can access it with all of the various webdav GUIs such as Konqueror, Cadaver, etc. by...
1
by: Drew | last post by:
Can I construct an HttpWebRequest with a local file instead of a URL? It seems like I remember doing this in Java with something like "file:\\\myfile.txt" in place of the URL. Thanks, Drew
2
by: George Durzi | last post by:
We recently upgraded to Exchange2K3/W2K3 from Exchange2K/W2K, and some of my c# code that I used to access users' contacts using WebDAV has stopped working. I'm getting a 401 unauthorized error....
4
by: John Smith | last post by:
Hey folks, I'm trying to communicate with our Exchange server using WebDav to get the User's personal contacts folder. Works fine if I hardcode their username and password (obviously not an...
0
by: Alex | last post by:
my app was working fine in VB.NET 2003 (and framework 1.1). Now with VB.NET 2005 (framework 2.0) the uploading to an http server (ie. www.sharebigfile.com) stops with the error "The request was...
0
by: arjen1984 | last post by:
I am now working on C# with WebDAV on Exchange now to get appointments. When I work local on the domain where the server is, i can get the appointments no problem. When I work outside of it, i get an...
1
by: WeCi2i | last post by:
Okay, I have a problem that has been stumping me for weeks. I have tried many different solutions and this is pretty much my last resort. I have seen a lot of good answers give here so I figured I...
1
by: tregewitz | last post by:
I am uploading a zip file using an HttpWebRequest and a PUT operation to Sharepoint (2003) from a Windows Form application. When I upload the same file using the Sharepoint Portal Web UI itself,...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
I need to programatically upload a text file to a web server using the HTTPWebRequest object within .Net 2.0. So far, I have determined that: - I need a HTTP content-type of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.