locked
full filename after post? RRS feed

  • Question

  • User-1194237341 posted

    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="nextpage.asp">
        <TABLE BORDER=0>
        <tr><td><b>Select a file to upload:</b><br><INPUT TYPE=FILE SIZE=50 NAME="FILE1"></td></tr>
       <tr><td align="center"><INPUT TYPE=SUBMIT VALUE="Upload!"></td></tr>
        </TABLE>
    </FORM>
     

     after uploading a file with a form, how would i get the full filename on the next page?

    Monday, October 15, 2007 11:17 PM

Answers

  • User743172522 posted

    We can use the following..... 

    <form id="form1" runat="server">

    <div>

    <input id="File1" style="width: 226px" type="file" runat="server" /><br />

    <input type="submit" id="Submit1" runat="Server" value="Upload File" OnServerClick="SubmitButton_Click">

    </div>

    </form>

     

    protected void SubmitButton_Click(object sender, EventArgs e)

    {

    if ((File1.PostedFile != null))

    {

    string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);

     Session["val"]=fn.ToString();

    Response.Write(fn);

    }

    }

    The value for the uploaded file is there in "fn". Using this string/session["Val'] we can get the value in the next page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 16, 2007 1:46 AM
  • User1702256038 posted

    Hi,

    Do you use the FileUpload control to upload the file?

     <asp:FileUpload ID="FileUpload1" runat="server" />
     <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" />

    You can use the FileUpload1's property filename to get the fullpath of the file. And use the System.IO.Path.GetFileName to get the full file's name.

    like:   System.IO.Path.GetFileName((this.FileUpload1.FileName));

     hope it helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 18, 2007 5:26 AM

All replies

  • User743172522 posted

    We can use the following..... 

    <form id="form1" runat="server">

    <div>

    <input id="File1" style="width: 226px" type="file" runat="server" /><br />

    <input type="submit" id="Submit1" runat="Server" value="Upload File" OnServerClick="SubmitButton_Click">

    </div>

    </form>

     

    protected void SubmitButton_Click(object sender, EventArgs e)

    {

    if ((File1.PostedFile != null))

    {

    string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);

     Session["val"]=fn.ToString();

    Response.Write(fn);

    }

    }

    The value for the uploaded file is there in "fn". Using this string/session["Val'] we can get the value in the next page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 16, 2007 1:46 AM
  • User1702256038 posted

    Hi,

    Do you use the FileUpload control to upload the file?

     <asp:FileUpload ID="FileUpload1" runat="server" />
     <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" />

    You can use the FileUpload1's property filename to get the fullpath of the file. And use the System.IO.Path.GetFileName to get the full file's name.

    like:   System.IO.Path.GetFileName((this.FileUpload1.FileName));

     hope it helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 18, 2007 5:26 AM