Click here to Skip to main content
15,917,731 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I finally figured how to get a image file upload function on MVC working but for some reason once the file uploads it's set it's not set to "exclude from project" status but I want to be able to display the uploaded image on the next "Completion page" once the upload is successful. Does anyone know how to set the default status of uploaded files to "include in project"? Not sure if it's a setting or a piece of code I need to implement.

C#
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult PersonalProfile()
{
    return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult PersonalProfile( string photo_filename)
{
    if (Request.Files["photo"] != null) // If uploaded synchronously
    {
        photo_filename = _fileStore.SaveUploadedFile(Request.Files["photo"]);

    }

   // ViewData["photo_guid"] = photo_guid.Value;
    ViewData["photo_filename"] = photo_filename;
    return View("Completed");
}


XML
</head>
    <body>
        <div id="MainContents">
            <h1>Thanks</h1>
            We have stored your photo <b><%= ViewData["photo_filename"]%></b>
            <br />
            <img src="" alt="" /> //image to be displayed
        </div>
    </body>
Posted
Updated 26-Dec-12 16:58pm
v2

If the file is on your server, you can use it. There is no project for it to be included in, you're not rebuilding your dll every time someone requests a page, are you ?
 
Share this answer
 
Comments
User1m 26-Dec-12 23:36pm    
No not rebuilding the dll... Its just that when the files are uploaded...You initially can't access the uploaded files unless you click "Show All Files" in the Solution Explorer
Christian Graus 26-Dec-12 23:39pm    
That is very odd. I have an MVC project where users upload images and they work right away.
User1m 26-Dec-12 23:51pm    
I'm going to post an image of the solution explorer below. Does my controller code look right?
Christian Graus 27-Dec-12 0:00am    
There is literally nothing you can mess up, so long as the file exists. Unless your issue is in the code that tries to look up the file, is it just not finding the right file ?
User1m 27-Dec-12 0:14am    
No the file exists int eh correct folder...but it's if I want to re-display the image from its path then I have to go in and click "include in project" before the image is visable
Just figured out what it was....I was uploading to a folder called "Files" in the ~/App_Data folder....once I moved "Files" to the root..everything works fine
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900