MVC upload file directory to shared directory

Source: Internet
Author: User

1. Need to add an account name with permissions (all permissions, including read, write, delete, and so on) to the server on the shared directory
The configuration node is added to the,<system.web> node in the 2.MVC site Webconfig file.
<identity impersonate= "true" username= "domain \ Account" password= "password"/>
3. When saving, you can save it directly

//------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------

<summary>///Save the file, write the uploaded file to the shared directory///</summary>///<param name= "file" ></param>///< param name= "Saveasfullname" ></param>///<returns></returns>protected PageActionReturn Saveuploadfile (httppostedfile file, string saveasfullname) {    pageactionreturn ret = new Pageactionreturn ();     try    {            if (string. IsNullOrEmpty (file. FileName)             {                 ret. IsOK = false;                ret. Message = "No specified file";           }            else    & nbsp       {                System.IO.FileInfo FileInfo = new System.IO. FileInfo (saveasfullname);                System.IO.DirectoryInfo folder = fileinfo.directory;                Createpath (folder);        & nbsp                       file. SaveAs (saveasfullname);                 ret. IsOK = true;                ret. Returndata = saveasfullname;            }          &nbsp ; }    catch (Exception ex)     {        ret. IsOK = false;        ret. Message = ex. message;        ret. StackTrace = ex. stacktrace;   }     return ret; }      



<summary>///Create a directory///If the directory does not exist, it has been created, provided that you have root permissions///</summary>///<param name= "folder" ></param >private void Createpath (System.IO.DirectoryInfo folder) {if (!folder. Exists) {if (!folder. parent.exists) {Createpath (folder.                Parent);} Folder.                     Create (); }           }

MVC upload file directory to shared directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.