Create File - CSharp File IO

CSharp examples for File IO:File

Description

Create File

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.IO;//from ww w . j a  va  2 s. c  om
using System.Collections.Generic;
using System;

public class Main{
        public static void CreateFile(string dir, string pagestr)
        {
            dir = dir.Replace("/", "\\");
            if (dir.IndexOf("\\") > -1)
                CreateDir(dir.Substring(0, dir.LastIndexOf("\\")));
            System.IO.StreamWriter sw = new System.IO.StreamWriter(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\" + dir, false, System.Text.Encoding.GetEncoding("GB2312"));
            sw.Write(pagestr);
            sw.Close();
        }
}

Related Tutorials