-1

So far I found something related to what I am looking for, but I'm not sure if this is what I need: link

How do I convert the file to byte in js and send it to webservices to upload to server.

Example:

JS:

<script>
    webService.UploadFile(Myfilebytes,suc,fail);
</script>

C#:

[Web Method]
public string UploadFile(byte[] Myfilebytes)
{
     //UPloading script
    return "OK";
}
1
  • I can't find how to change my file into byte.Thank yOu Commented Jan 24, 2013 at 19:08

1 Answer 1

0

You don't convert the file to a byte array; it already is one. Your browser manages the responsibility of formatting the data to send to a web service. Typically this is achieved through a POST on a form with an input of type file:

<form enctype="multipart/form-data" action="UploadFile" method="post">
    <input id="image" type="file" />
</form>

Using a WebMethod on the C# side is not possible, however, as POST variables are received through the request information, of which a WebMethod does not provide. You can create a web handler and use the ProcessRequest method to receive this info, but this is not the only way.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I found this link stackoverflow.com/questions/7431365/… , but I can't get it wokk. How can I implement it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.