SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2013
    Posts
    64
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Help please if you know how to upload a file!!!

    Hi
    I'm trying to upload a file to my web-site using the code below.

    I've marked where it crashes where it says:-
    strFileName = Path.GetFileName(theImage.FileName); /* Crashing on this line !!!!!!!!!!!!!!!!!!!!

    I'm really stumped. Please can anyone get me going again.

    This is my code :-

    @{
    var image = "";

    WebImage theImage = null;
    var strFileName="";
    var strImgPath="";

    if (IsPost){
    theImage = WebImage.GetImageFromRequest();

    strFileName = Path.GetFileName(theImage.FileName); /* Crashing on this line !!!!!!!!!!!!!!!!!!!!
    strImgPath = @"images\" + strFileName;
    theImage.Save(@"~\"+strImgPath);
    }
    }

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>The Matrix Man</title>
    <link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <!-- This is start of a new website that is going to reach new heights of design never seen before -->
    <div id="header">
    </div> <!-- end of header div -->

    <div id="bodycontent">
    <form action="" method="post" enctype="multipart/form-data">
    Enter you file path to upload an image...
    <input type="file" name="image" value="@image" />
    <input type="submit" value="Upload" />
    </form>
    </div> <!-- end of bodycontent div -->

    </body>
    </html>

    Cheers
    Matt

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2013
    Posts
    64
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Its ok - a pc reboot fixed this - not sure how though!!

    cheers
    Matt


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
  •