S
Shannon Hardin
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
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