What I want to do:
Upload a file to autoCAD server and display a URN received from the server.
What I am currently doing:
Upload the file using <asp:FileUpload>
control;
Get the uploaded file object from code behind using:HttpPostedFile myFile = FileUpload1.PostedFile;
The code behind will return a string called FileURN
, it will be shown in a textarea using:
<textarea class="form-control" readonly="readonly" rows="5" id="txt_resUploadFile"><%= FileURN %></textarea>
The problem:
The html page gets refreshed every time the upload button is clicked. I understand that the full page gets refreshed when a trip to server is made. So I wanted to use AJAX for that. But soon I realize AJAX calls only Webmethod, which has to be static. Since HttpPostedFile myFile = FileUpload1.PostedFile;
is no longer working in a static method, How can I get uploaded file stream?
Code Snippet:
html:
<div>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br/>
<asp:Button class=" btn btn-primary col-md-2" ID="btnUpload" runat="server" Text="Upload file" onclick="btnUpload_Click" />
</div>
</form>
<textarea class="form-control" readonly="readonly" rows="5" id="txt_resUploadFile"><%= FileURN %></textarea>
Codebehind:
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
HttpPostedFile myFile = FileUpload1.PostedFile;
//send myFile to autoCAD server and get result from that server....
}
FileURN = "The Result";