简体   繁体   中英

How do I lead client to another page and modify an uploaded file in the code-behind in .NET?

Right now in my HTML I have:

<asp:FileUpload ID="fileUpload" runat="server" />
<asp:Button ID="pbcUploadBtn" runat="server" Text="Upload" onclick="uploadBtnClick" />

In my code-behind:

protected void uploadBtnClick(object sender, EventArgs e)
{
    if (this.fileUpload.HasFile)
    {
        this.fileUpload.SaveAs(Server.MapPath("~/upload/") + this.fileUpload.FileName);
    }
}

Is it possible to, on the click of the button, call javascript to lead the user to the next page (FileEditor.aspx). I need to lead the user to the next page while keeping the filename so it can operate on it with XmlDocument methods. How do I pass back the GUID generated in the uploadBtnClick() method? I'm guessing the second page will have another code-behind, so I'm not sure how I can operate on that specific file?

After you save the uploaded file, you can use Server.Transfer to load the next page in your flow without changing the URL. This will, however, still cause the page to go through the entire ASP.NET life cycle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM