473,655 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y 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 MyCredentialCac he = New System.Net.Cred entialCache
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(WebReques t.Create(Source URI),
HttpWebRequest)

Try

MyCredentialCac he.Add(New System.Uri(Sour ceURI), "NTLM", New
System.Net.Netw orkCredential(U serName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Crede ntials = MyCredentialCac he
MyRequest.Heade rs.Add("Destina tion",
"http://DestinationServ er/SubFolder/text.xml")
MyRequest.Heade rs.Add("Overwri te", "F")
MyRequest.Metho d = "COPY"
MyResponse = CType(MyRequest .GetResponse(), HttpWebResponse )
MyResponse.Clos e()

Catch ex As Exception
MsgBox(ex.Messa ge)
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 15415
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******** ******@TK2MSFTN GP10.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 MyCredentialCac he = New System.Net.Cred entialCache
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(WebReques t.Create(Source URI),
HttpWebRequest)

Try

MyCredentialCac he.Add(New System.Uri(Sour ceURI), "NTLM", New
System.Net.Netw orkCredential(U serName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Crede ntials = MyCredentialCac he
MyRequest.Heade rs.Add("Destina tion",
"http://DestinationServ er/SubFolder/text.xml")
MyRequest.Heade rs.Add("Overwri te", "F")
MyRequest.Metho d = "COPY"
MyResponse = CType(MyRequest .GetResponse(), HttpWebResponse )
MyResponse.Clos e()

Catch ex As Exception
MsgBox(ex.Messa ge)
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*********@gm x.net> wrote in message
news:3R******** ********@newsre ad1.news.pas.ea rthlink.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******** ******@TK2MSFTN GP10.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 MyCredentialCac he = New System.Net.Cred entialCache
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(WebReques t.Create(Source URI), HttpWebRequest)

Try

MyCredentialCac he.Add(New System.Uri(Sour ceURI), "NTLM", New
System.Net.Netw orkCredential(U serName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Crede ntials = MyCredentialCac he
MyRequest.Heade rs.Add("Destina tion",
"http://DestinationServ er/SubFolder/text.xml")
MyRequest.Heade rs.Add("Overwri te", "F")
MyRequest.Metho d = "COPY"
MyResponse = CType(MyRequest .GetResponse(), HttpWebResponse )
MyResponse.Clos e()

Catch ex As Exception
MsgBox(ex.Messa ge)
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 MyCredentialCac he = New System.Net.Cred entialCache
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(WebReques t.Create(Source URI),
HttpWebRequest)

Try

MyCredentialCac he.Add(New System.Uri(Sour ceURI), "NTLM", New
System.Net.Netw orkCredential(U serName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Crede ntials = MyCredentialCac he
MyRequest.Heade rs.Add("Destina tion",
"http://DestinationServ er/SubFolder/text.xml")
MyRequest.Heade rs.Add("Overwri te", "F")
MyRequest.Metho d = "COPY"
MyResponse = CType(MyRequest .GetResponse(), HttpWebResponse )
MyResponse.Clos e()

Catch ex As Exception
MsgBox(ex.Messa ge)
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
"santoshpot dar" <sa************ ******@mail.mcs e.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 MyCredentialCac he = New System.Net.Cred entialCache
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(WebReques t.Create(Source URI),
HttpWebRequest)

Try

MyCredentialCac he.Add(New System.Uri(Sour ceURI), "NTLM", New
System.Net.Netw orkCredential(U serName, Password, Domain))

' Add the network credentials to the request.
MyRequest.Crede ntials = MyCredentialCac he
MyRequest.Heade rs.Add("Destina tion",
"http://DestinationServ er/SubFolder/text.xml")
MyRequest.Heade rs.Add("Overwri te", "F")
MyRequest.Metho d = "COPY"
MyResponse = CType(MyRequest .GetResponse(), HttpWebResponse )
MyResponse.Clos e()

Catch ex As Exception
MsgBox(ex.Messa ge)
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
4976
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 using a URL like this: webdavs://dav.hostname.com/user_name/uploads My goal is to upload files automatically with a python script. The server requires authentication over SSL which I can do with urllib2 like this:
1
6422
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
2785
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. Hopefully, I can explain this adequately. Prior to the upgrade the following code was working properly. FYI: The site was running in the context of the domain administrator, and was also using the Administrator account to create a CredentialCache...
4
7960
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 acceptable solution), but when I use Integrated Authentication I get "(401) Unauthorized". I've got <identity impersonate="true" /> and I've got <authentication mode="Windows" />, and I've set up IIS to use Windows Authentication. I know this...
0
7262
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 aborted: The request was canceled" after about 7 MB. For example, I might be uploading a 73MB file. After about 11% done the upload aborts. :shake: It works great for files < 5MB. I can upload those every time.
0
3394
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 SecurityException. This is my code to get the appointments: protected void getAfspraken() { NetworkCredential credential = new NetworkCredential("bhees","1234567", "oaicttest"); WebdavSession session = new...
1
4409
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 would give it a try. First of all, I am using Visual Studio 2005 to write my program. I am using C# .NET as the language. I am running Windows XP Professional with all service packs and updates applied. Now, I have been trying to write a...
1
4563
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, the file uploads in 1/3 the time. If I copy the file over the network using Windows Explorer, it also copies in about 1/3 of the time. I don't understand why it is taking so much longer transferring it in this way. I've tried several...
3
4221
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 "multipart/form-data". - I need to use the ContentType.Boundary property. That is about as far as I have gotten.
0
8380
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8598
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.