0

i am using file upload control in ASP.NET for uploading images. In my form there are two buttons.one for assigning criteria which redirects to other form and other for submitting form. After assigning criteria only the user has to use submit button.

My problem is when is upload image and click on AssignCriteria button and return back to original page,the upload control is getting blank. How to keep that upload image control value in that textbox even if we redirected to other page and come back.

2 Answers 2

1
<asp:FileUpload runat="server" ID="uploadStatement" />
<asp:Button runat="server" Text="Upload" OnClick="cmdUpload_Click" />

Next code uploads selected file to Temp folder on the server, in my case - parses it and deletes the file.

    protected void cmdUpload_Click(object sender, EventArgs e)
    {
        var fileName = Server.MapPath(Path.Combine("Temp", String.Concat(Guid.NewGuid().ToString(), Path.GetExtension(uploadStatement.FileName))));
        try
        {
            uploadStatement.SaveAs(fileName);

            // parse file
        }
        finally
        {
            File.Delete(fileName);
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Since any manipulation with the "input type='file'" element is a serious security threat I am afraid there is no way to do this.

Have you considered using of some AJAX overlay "dialog"?

Comments

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.