473,511 Members | 15,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15396
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
4952
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
6347
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
2779
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
7949
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
7233
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
3387
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
4402
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
4526
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
4216
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
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.