G
Guest
Im trying to upload a file to a iis server.
But im always getting an error.
Can u help me, looking at my code or giving some tips?
I saw another post with prob related to httpwebrequest, it seems it worked for them...
But it seems luck doesnt want anything with me
Thx in advance
public void UploadFileBinary(string localFile, string uploadUrl)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
req.Method = "PUT";
req.AllowWriteStreamBuffering = true;
// Retrieve request stream
Stream reqStream = req.GetRequestStream();
StreamWriter wrtr = new StreamWriter(reqStream);
// Open the local file
FileStream rdr = new FileStream(localFile, FileMode.Open);
// Allocate byte buffer to hold file contents
byte[] inData = new byte[4096];
// loop through the local file reading each data block
// and writing to the request stream buffer
int bytesRead = rdr.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
reqStream.Write(inData, 0, bytesRead);
bytesRead = rdr.Read(inData, 0, inData.Length);
}
rdr.Close();
wrtr.Close();
reqStream.Close();
req.GetResponse();
}
But im always getting an error.
Can u help me, looking at my code or giving some tips?
I saw another post with prob related to httpwebrequest, it seems it worked for them...
But it seems luck doesnt want anything with me
Thx in advance
public void UploadFileBinary(string localFile, string uploadUrl)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
req.Method = "PUT";
req.AllowWriteStreamBuffering = true;
// Retrieve request stream
Stream reqStream = req.GetRequestStream();
StreamWriter wrtr = new StreamWriter(reqStream);
// Open the local file
FileStream rdr = new FileStream(localFile, FileMode.Open);
// Allocate byte buffer to hold file contents
byte[] inData = new byte[4096];
// loop through the local file reading each data block
// and writing to the request stream buffer
int bytesRead = rdr.Read(inData, 0, inData.Length);
while (bytesRead > 0)
{
reqStream.Write(inData, 0, bytesRead);
bytesRead = rdr.Read(inData, 0, inData.Length);
}
rdr.Close();
wrtr.Close();
reqStream.Close();
req.GetResponse();
}