SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question I'm trying to upload a file in ASP.NET C#

    Here's my form...

    HTML Code:
    <form method="post" enctype="multipart/form-data">
       <input type="file" name="filScreenshot" id="filScreenshot" /><br />
       <input type="submit" name="btnSubmit" value="Submit" />
    </form>
    How does my .NET code need to look in order to upload a file? I've searched all over, but there seems to be so many ways to do it and none are really working.

    Thanks!

  2. #2
    SitePoint Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where is the backend and button action?
    Are you in Visual Studio? it's C# or VB.Net?
    This code will not work at all.

  3. #3
    SitePoint Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by GeorgL View Post
    Where is the backend and button action?
    Are you in Visual Studio? it's C# or VB.Net?
    This code will not work at all.
    C#. I have all the backend code in place except for the code that takes the selected file from filScreenshot and uploads it to my server.

  5. #5
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by GeorgL View Post

    I'm trying baby steps. What can I use to ensure a file was uploaded? Nothing in those links are working for me.

    For example...

    Code:
    Request.Files["filScreenshot"].HasFile
    That gives me this error: 'System.Web.HttpPostedFile' does not contain a definition for 'HasFile'

  6. #6
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found something that works. I can take it from here. Thanks!

    Code:
    if (Request.Files.Count > 0) {
         HttpPostedFile file = Request.Files[0];
         file.SaveAs(Server.MapPath("images/myFile.jpg"));
    }

  7. #7
    SitePoint Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Download Visual Web Developer at Microsoft. http://www.asp.net/vwd
    You should start coding in a visual environmen, with auto complete abilities it's more easy to do jobs! you are coding like ASP3 Classic in ASP.Net. but everything has changed, You have fundamental problems in your codes.

  8. #8
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <form id="form1" runat="server">
        <div>
            <h2>Upload File</h2>
    
            <asp:FileUpload ID="fuUpload" runat="server" />
            <asp:Button ID="btnUpload" runat="server" onclick="btnUpload_Click" 
                Text="Upload" />
    
            <p><asp:Label ID="lblInform" runat="server"></asp:Label></p>
        </div>
        
        </form>
    hop this helpful

  9. #9
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,633
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    That doesn't -- you don't even have a key attribute on the form to make it post uploaded files.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •