0

I have an action method on which i post the file and then , i need to upload or save this file on server in some temp location and read the data from that file.

public static string UploadFile(HttpPostedFileBase file)
{
file.SaveAs(tempfileuploadpath);
}

Now when i write above code, does this mean that now the content of file would be read from the tempfileuploadpath or it will still be holding the reference to user local upload directory.

Please help.I am new to this :)

user1595214
  • 521
  • 3
  • 10
  • 22
  • The path of the file is never sent to the server when you uplodd a file (just the file name). There is no knowledge of the _ user local upload directory_ let alone a reference to it. –  Feb 10 '16 at 10:07
  • Yes i just explored it.My problem is i want to convert the file uploaded to the server to httppostedfilebase type and use it to my other functions which performs validation using propeties like content type and content length.I do created a custom class derived from httppostedfilebase, and assigning the value of newly created file in server to this object,but i m not sure if this is correct approach. – user1595214 Feb 10 '16 at 10:24
  • Not sure what your saying - the parameter in your method is `HttpPostedFileBase` (you do not need to convert it again). And if your wanting validation, then consider using validation attribute, for example [this answer](http://stackoverflow.com/questions/33414158/checking-image-mime-size-etc-in-mvc/33426397#33426397) for validating the file type –  Feb 10 '16 at 10:32

0 Answers0