How do i read files form html control to C# code and how to save in server?
I have one html input control in my html page. When i click on upload i want to save that file in server folder using .net code. but how can i read and save that file.
Below is my code,
Angular js side code,
function RRUplaod() {
var File;
File = $('#FileUpload')[0].files[0];
if (File != "") {
var fileName = File.name;
fileName = fileName + '^' + id
var xhr = new XMLHttpRequest();
var url = //service url
xhr.open('POST', url, true);
xhr.setRequestHeader("FN", fileName);
inviteFileName = fileName;
xhr.onreadystatechange = function () {
};
xhr.send(File);
}
C# code
public UploadedFile UplaodFile(Stream Uploading)
{
IncomingWebRequestContext woc = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = woc.Headers;
string fileName = "";
string id= "";
fileName = headers["FN"].Split('^')[0];
id= headers["FN"].Split('^')[1];
UploadedFile upload = new UploadedFile
{
FilePath = Path.Combine(HttpContext.Current.Server.MapPath(".") + "\\Document\\", fileName)
};
FileStream fs = new FileStream(upload.FilePath, FileMode.Open, FileAccess.Read);
byte[] ImageData = new byte[fs.Length];
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
}
but i dont know how to save that file using c# code...
Please help