C # create a file or folder if the file or folder does not exist

Source: Internet
Author: User

Using system. IO;
String Path = @ "D: \ accountdaoru \";
If (directory. exists (PATH) = false)
{
Directory. createdirectory (PATH );
}

If (directory. exists (server. mappath (~ /Upimg/hufu) = false) // create a file folder {directory. createdirectory (server. mappath (~ /Upimg/hufu);} // directory. Delete (server. mappath (~ /Upimg/hufu), true); // delete folders and subdirectories in folders, and determine the existence of files if (file. exists (server. mappath (~ /Upimg/data.html) {response. Write (yes); // file} else {response. Write (NO); // file. Create (mappath (~ /Upimg/data.html); // create the file} string name = getfiles. filename; // get the name of the uploaded file string size = getfiles. postedfile. contentlength. tostring (); // obtain the size of the uploaded file string type = getfiles. postedfile. contenttype; // obtain the mimestring Postfix = Name of the uploaded file. substring (name. lastindexof (.) + 1); // obtain the suffix string ipath = server of the uploaded file. mappath (upimg) + \\+ name; // obtain the actual file path string fpath = server. mappath (upfile) + \\+ name; string dpath = upimg \ + name; // judge the virtual path showpic written to the database. visible = true; // activate showtext. visible = true; // activate // determine the file format if (name =) {response. write (<scriptalert ('upload file cannot be blank ') </script );} else {If (Postfix = JPG | Postfix = GIF | Postfix = BMP | Postfix = PNG) {getfiles. saveas (ipath); showpic. imageurl = dpath; showtext. TEXT = The Name Of The uploaded image is + name ++ file size: + size + kb ++ file type: + type ++ the actual storage path is + ipath ;} else {showpic. visible = false; // hide the image getfiles. saveas (fpath); // as it is not an image file, the folder showtext is converted to upfile. TEXT = the name of the uploaded file is + name ++ file size: + size + kb ++ file type: + type ++ the actual storage path is + fpath ;}
Related Article

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.