0

I am uploading a file in MVC3 my csHtml page is

<div class="editor-label">
    @Html.LabelFor(model => model.Resume)
</div>
<div class="editor-field">
        <input type="file" name="Resume" id="Resume"   />
        @* @Html.EditorFor(model => model.ImageData)*@
    @Html.ValidationMessageFor(model => model.Resume)

</div>

My Post Method is

[HttpPost] public ActionResult SignUp(UserView user) {

    try
    {
        if (ModelState.IsValid)
        {
            UserManager userManager = new UserManager();
            if (!userManager.IsUserLoginIDExist(user.LoginID))
            {
               // Request.Params["Resume"];
                 userManager.Add(user,Request.Files["Resume"]);
                FormsAuthentication.SetAuthCookie(user.FirstName, false);
                return RedirectToAction("Welcome", "Home");

            }
          }
    }

    catch
    {
        return View(user);
    }

    return View(user);
}

and my Model is

        public class UserView
{
    [Required]
    [Display(Name = "First Name")]
    public string FirstName { get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Required]
    [Display(Name = "Contact Number")]
    public string ContactNumber { get; set; }

    [Required]
    [Display(Name = "Login ID")]
    public string LoginID { get; set; }

    [Required]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Required]
    [Display(Name = "Resume")]
    public string Resume { get; set; }
  }
 }

I am getting user.Resume's value as full path(C:\test.png) on some machine and on some machine i am getting just name of the file(test.png). Please help me to deal with this miscellaneous issue

Rutu
  • 147
  • 2
  • 10

1 Answers1

0

You aren't actually saving the file there at the moment. Perhaps you know this and have left the code out for brevity, but ASP.Net's built-in file handling gives you everything you need.

This question gives you all the info you need: File Upload Asp.net Mvc3.0

Community
  • 1
  • 1
Steve Owen
  • 2,022
  • 1
  • 20
  • 30
  • i am saving file but i haven't posted the code but the issue here with code is user.Resume that is path of the file gives only the file name not full path e.g.C:\Test.png on some machine and on some machines it gives full path – Rutu Jul 11 '12 at 09:22
  • Presumably you don't want the full path though, do you? That's going to be the user's path on their system. If you just want the filename you can use Path.GetFilename() which would return the filename whether you supply just the filename or the full path. – Steve Owen Jul 11 '12 at 11:59