Upload file using asp.net webservice
Hello I want to upload file from webservice not WCF.I am using C# and consuming it with web application.From web application send file,and service will accept that file(text file) and place in upload folder of website/or given location.For this I have created Like this
: For making webservice
created empty web application -> selected new Item -> Web service
1> Wrote following code in webservice
[WebMethod]
public void UploadFile()
{
FileStream targetStream = null;
Stream sourceStream = FileByteStream;
string uploadFolder = @"D:\UploadFile";
string filePath = Path.Combine(uploadFolder, @"C:\Users\maya\Desktop\test.txt");
using (targetStream = new FileStream(filePath, FileMode.Create,
FileAccess.Write, FileShare.None))
{
//read from the input stream in 65000 byte chunks
const int bufferLen = 65000;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
// save to output stream
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}
}
Here my not taking any input,I have manual entered one text file.I want to transfer that file to uploadfolder. I am getting error(HTTP 500 Internal server error) at this line.while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0).How to handle this.