当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.Delete方法代码示例

本文整理汇总了C#中FileInfo.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Delete方法的具体用法?C# FileInfo.Delete怎么用?C# FileInfo.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileInfo的用法示例。


在下文中一共展示了FileInfo.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoctorScheduleSyncer

    public bool DoctorScheduleSyncer()
    {
        #region Variable
        clsSQL clsSQL = new clsSQL();
        FileInfo fi = new FileInfo(System.Web.HttpContext.Current.Server.MapPath("/Upload/Doctor/SQLQuery.txt"));
        string sqlQuery = "";
        bool result = false;
        #endregion

        if (fi.Exists)
        {
            StreamReader StrWer;
            try
            {
                StrWer = File.OpenText(System.Web.HttpContext.Current.Server.MapPath("/Upload/Doctor/SQLQuery.txt"));
                while (!(StrWer.EndOfStream))
                {
                    sqlQuery = sqlQuery + StrWer.ReadLine();
                }
                StrWer.Close();
            }
            catch (Exception) { }

            if (sqlQuery != "")
            {
                clsMail clsMail = new clsMail();
                string outMail = ""; string outSQLError = "";
                if (!clsSQL.Execute(sqlQuery, dbType, cs,out outSQLError))
                {
                    clsMail.Send("[email protected]", "[email protected]",
                        "DoctorScheduleSyncer : Error Insert (OnWeb)",
                        outSQLError + "<hr/>"+sqlQuery, out outMail);
                    //lblDoctorScheduleSyncer.Text = "DoctorScheduleSyncer : เกิดข้อผิดพลาดขณะรันคำสั่ง<br/>"+sqlQuery;
                    fi.Delete();
                }
                else
                {
                    fi.Delete();
                    result = true;
                }
            }
        }
        else
        {
            result = true;
        }

        return result;
    }
开发者ID:oofdui,项目名称:ChanthaburiHospital.com,代码行数:49,代码来源:clsSyncer.cs

示例2: importData_Click

 protected void importData_Click(object sender, EventArgs e)
 {
     if (!dataFileUpload.HasFile)
         return;
     var shortFileName = Guid.NewGuid() + ".csv";
     var filename = ConfigurationManager.AppSettings["WorkDir"] + shortFileName;
     if (File.Exists(filename))
         File.Delete(filename);
     dataFileUpload.SaveAs(filename);
     var fileInfo = new FileInfo(filename);
     try
     {
         using (
             var conn =
                 new MySqlConnection(
                     ConfigurationManager.ConnectionStrings["oktrackerConnectionString"].ConnectionString))
         {
             conn.Open();
             var command = conn.CreateCommand();
             command.CommandText = "LOAD DATA INFILE '" + fileInfo.FullName.Replace('\\', '/') +
                                   "' INTO TABLE `release`" +
                                   " columns TERMINATED BY ',' OPTIONALLY ENCLOSED BY '" + '"' +
                                   "'LINES TERMINATED BY '\n'" +
                                   " (user_id,title,releasestatus_id,description,`size`)";
             command.ExecuteNonQuery();
             conn.Close();
             fileInfo.Delete();
             Response.Redirect("~/Default.aspx", true);
         }
     }
     catch (Exception exception)
     {
     }
 }
开发者ID:spencarik,项目名称:OkTracker_git,代码行数:34,代码来源:Admin.aspx.cs

示例3: exportData_Click

 protected void exportData_Click(object sender, EventArgs e)
 {
     var shortFileName = Guid.NewGuid() + ".csv";
     var filename = ConfigurationManager.AppSettings["WorkDir"] + shortFileName;
     var fileInfo = new FileInfo(filename);
     if (fileInfo.Exists)
     {
         fileInfo.Delete();
     }
     try
     {
         using (
             var conn =
                 new MySqlConnection(
                     ConfigurationManager.ConnectionStrings["oktrackerConnectionString"].ConnectionString))
         {
             conn.Open();
             var command = conn.CreateCommand();
             command.CommandText =
                 "select user_id,title,releasestatus_id,description,`size` from `release` into outfile '" + fileInfo.FullName.Replace('\\', '/') +
                 "' columns TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'";
             command.ExecuteNonQuery();
             conn.Close();
         }
         Response.Redirect("~/FileHandler.ashx?type=cvs&file=" + shortFileName);
     }
     catch (Exception exception)
     {
     }
 }
开发者ID:spencarik,项目名称:OkTracker_git,代码行数:30,代码来源:Admin.aspx.cs

示例4: WriteLogFile

    public static void WriteLogFile(String input, string filePath)
    {
        //定义文件信息对象
        FileInfo finfo = new FileInfo(filePath);

        //判断文件是否存在以及是否大于2M
        if (finfo.Exists && finfo.Length > 2047500)
        {
            //删除该文件
            finfo.Delete();
        }
        //创建只写文件流
        using (FileStream fs = finfo.OpenWrite())
        {
            //根据上面创建的文件流创建写数据流
            StreamWriter w = new StreamWriter(fs);
            //设置写数据流的起始位置为文件流的末尾
            w.BaseStream.Seek(0, SeekOrigin.End);
            //写入“Log Entry : ”
            w.Write("\r\nLog Entry : ");
            //写入当前系统时间并换行
            w.Write("{0} {1} \r\n", DateTime.Now.ToLongTimeString(),
                DateTime.Now.ToLongDateString());
            //写入日志内容并换行
            w.Write(input + "\r\n");
            //写入------------------------------------“并换行
            w.Write("------------------------------------\r\n");
            //清空缓冲区内容,并把缓冲区内容写入基础流
            w.Flush();
            //关闭写数据流
            w.Close();
        }
    }
开发者ID:lakeli,项目名称:shizong,代码行数:33,代码来源:Logger.cs

示例5: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["objSessionvalueAdmin"] == null)
        {
            string fileName = Server.MapPath("~/Common") + "\\User.xml";
            if (File.Exists(fileName))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(fileName);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int UserID = Convert.ToInt16(ds.Tables[0].Rows[0][0].ToString());
                    string UserName = ds.Tables[0].Rows[0][1].ToString();
                    string FirstName = ds.Tables[0].Rows[0][2].ToString();
                    string LastName = ds.Tables[0].Rows[0][3].ToString();
                    bool IsUsernameVisiable = Convert.ToBoolean(ds.Tables[0].Rows[0][4].ToString());

                    SetSessionValue(UserID,UserName,FirstName,LastName,IsUsernameVisiable);
                    FileInfo objfile = new FileInfo(fileName);
                    if (objfile.Exists)
                    {
                        objfile.Delete();
                    }
                }
              }
            else
            {
                Response.Redirect("AdmintratorLogin.aspx");
            }
        }
    }
开发者ID:rupendra-sharma07,项目名称:MainTrunk,代码行数:31,代码来源:PortalAdmin.master.cs

示例6: WriteFile

    //  写文件 
    static string WriteFile(string flt)
    {
#if UNITY_ANDROID
    #if UNITY_EDITOR
            string filePathName = "C:/" + flt.ToString() + ".txt";
    #else
        	string filePathName = "jar:file://" + Application.dataPath + "!/assets/"+ flt.ToString() + ".txt";
	#endif
#elif UNITY_STANDALONE_WIN
	#if UNITY_EDITOR
			string filePathName = "C:/" + flt.ToString() + ".txt";
	#else
			string filePathName = Application.dataPath + "/" + flt.ToString() + ".txt";
	#endif
#elif UNITY_IPHONE
	string filePathName = Application.dataPath + "/" + flt.ToString() + ".txt";
#else
	string filePathName = Application.dataPath + "/" + flt.ToString() + ".txt";
#endif
        if (LogFileDic.ContainsKey(flt))
        return filePathName;

        FileInfo TheFile = new FileInfo(filePathName);   
        if (TheFile.Exists)   
            TheFile.Delete();

        StreamWriter fileWriter = File.CreateText(filePathName); 
        fileWriter.Close();

        LogFileDic.Add(flt, true);

        return filePathName;
    }
开发者ID:seenen,项目名称:HerosTechBak_Seenen,代码行数:34,代码来源:LogFile.cs

示例7: OnApplicationQuit

    void OnApplicationQuit()
    {
        string playerId = Extensions.Player.playerId;
        #if UNITY_EDITOR

        if(Extensions.Player.controlType==PlayerBeheaver.ControlType.mono){

            FileInfo f = new FileInfo( Application.persistentDataPath + "\\" + playerId+".txt");
            StreamWriter w;
            if(!f.Exists)
            {
                w = f.CreateText();
            }
            else
            {
                f.Delete();
                w = f.CreateText();
            }
            //w.WriteLine(loadMessage);
            w.WriteLine (playerId);
            foreach(StageStatistic s in statistics){
                w.WriteLine(s.gameObject.name+", "+s.counter.ToString());
            }

            w.Close();
            Debug.Log("saves");
        }
        #endif
    }
开发者ID:Cabris,项目名称:unity_lab,代码行数:29,代码来源:StagesStatistic.cs

示例8: Export

 public virtual bool Export(string key, FileInfo fileInfo)
 {
     var callingAssembly = Assembly.GetCallingAssembly();
     fileInfo.Directory.Create();
     try
     {
         if (fileInfo.Exists)
         {
             fileInfo.IsReadOnly = false;
             fileInfo.Delete();
         }
         using (var resource = callingAssembly.GetManifestResourceStream(string.Format("{0}.Resources.{1}", callingAssembly.GetName().Name, key)))
         using (var stream = fileInfo.OpenWrite())
         {
             resource.CopyTo(stream);
         }
         return true;
     }
     catch (IOException)
     {
         return false;
     }
     catch (UnauthorizedAccessException)
     {
         return false;
     }
     catch (Exception)
     {
         //TODO: log
         return false;
     }
 }
开发者ID:Z731,项目名称:NotifyPropertyWeaver,代码行数:32,代码来源:ResourceExporter.cs

示例9: btn_download_Click

    protected void btn_download_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.TableName = "All_Contacts";
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dlgf"].ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("[CTX].[sp_Select_All_List]", conn);
            conn.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            adapter.Fill(dt);
            conn.Close();
        }

        string dir = Server.MapPath("All_List_output");
        string milli = DateTime.Now.Millisecond.ToString();
        FileInfo newFile = new FileInfo(dir + @"\CTX_"+ milli + ".xlsx");
        if (newFile.Exists)
        {
            newFile.Delete();  // ensures we create a new workbook
            newFile = new FileInfo(dir + @"\CTX_" + milli + ".xlsx");
        }

        using (ExcelPackage pack = new ExcelPackage(newFile))
        {
            ExcelWorksheet ws = pack.Workbook.Worksheets.Add(dt.TableName.ToString());
            ws.Cells["A1"].LoadFromDataTable(dt, true);
            pack.Save();
        }

        string path = dir + @"\" + newFile.Name;
        Response.ContentType = "application/excel";
        Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + newFile.Name + "\""); //file name must be in double quotes to allow spaces in the filename
        Response.TransmitFile(path);
        Response.End();
    }
开发者ID:243,项目名称:ConTAX,代码行数:35,代码来源:AllContacts.aspx.cs

示例10: Main

    static void Main(string[] args)
    {
        var sourceDoc = new FileInfo("../../TestDocument.docx");
        var newDoc = new FileInfo("Modified.docx");
        if (newDoc.Exists)
            newDoc.Delete();
        File.Copy(sourceDoc.FullName, newDoc.FullName);
        using (WordprocessingDocument wDoc = WordprocessingDocument.Open(newDoc.FullName, true))
        {
            int count;
            var xDoc = wDoc.MainDocumentPart.GetXDocument();
            Regex regex;
            IEnumerable<XElement> content;

            content = xDoc.Descendants(W.p);
            regex = new Regex("[.]\x020+");
            count = OpenXmlRegex.Replace(content, regex, "." + Environment.NewLine, null);

            foreach (var para in content)
            {
                var newPara = (XElement)TransformEnvironmentNewLineToParagraph(para);
                para.ReplaceNodes(newPara.Nodes());
            }

            wDoc.MainDocumentPart.PutXDocument();
        }
    }
开发者ID:BogdanDamianC,项目名称:Open-Xml-PowerTools,代码行数:27,代码来源:OpenXmlRegex02.cs

示例11: deletefilesfrfolder

 public void deletefilesfrfolder(string del_directory)
 {
     string[] mainfiles = Directory.GetFiles(del_directory);
     if (mainfiles.Length > 0)
     {
         foreach (string mainfile in mainfiles)
         {
             FileInfo fi = new FileInfo(mainfile);
             fi.Attributes = FileAttributes.Normal;
             fi.Delete();
         }
     }
     string[] folders = Directory.GetDirectories(del_directory);
     if (folders.Length > 0)
     {
         foreach (string folder in folders)
         {
             deletefilesfrfolder(folder);
             if (Directory.Exists(folder))
             {
                 Directory.Delete(folder, true);
             }
         }
     }
     Directory.Delete(del_directory, true);
 }
开发者ID:wpdildine,项目名称:wwwroot,代码行数:26,代码来源:file.ascx.cs

示例12: CopyFile

	void CopyFile(string src_path, string tar_oath){
		string path = src_path;
		string path2 = tar_oath;
		FileInfo fi1 = new FileInfo(path);
		FileInfo fi2 = new FileInfo(path2);
		
		try 
		{
			// Create the file and clean up handles.
			using (FileStream fs = fi1.Create()) {}
			
			//Ensure that the target does not exist.
			fi2.Delete();
			
			//Copy the file.
			fi1.CopyTo(path2);
			
			//Try to copy it again, which should succeed.
			fi1.CopyTo(path2, true);

		} 
		catch 
		{

		}
	}
开发者ID:xiaopangoo,项目名称:MotionPlatform,代码行数:26,代码来源:Newtask.cs

示例13: Main

    public static void Main(string[] args)
    {
        FileInfo file = new FileInfo(@"..\..\CopyDelete.cs");
        string fullPath =file.FullName;
        DirectoryInfo dir = new DirectoryInfo(@"..\..\");
        dir.CreateSubdirectory("backup");
        DirectoryInfo backupDir = new DirectoryInfo(@"..\..\backup");
        foreach (FileInfo subfile in backupDir.GetFiles())
        {
            subfile.Delete();
        }
        file.CopyTo(@"..\..\backup\CopyDelete_Backup.cs");

        DirectoryInfo tempDir = new DirectoryInfo(@"..\..\temp");
        tempDir.Create();
        FileInfo tempFile = new FileInfo(@"..\..\temp\temp.txt");
        FileStream fs = tempFile.Create();

        fs.Close();
        tempFile.Delete();
        tempDir.Delete(true);

        Console.WriteLine("All done.");
        Console.ReadLine();
    }
开发者ID:Nagato23,项目名称:CsBasic,代码行数:25,代码来源:CopyDelete.cs

示例14: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Convert.ToString(Request["id"]);
        if (!String.IsNullOrEmpty(id))
        {
            //1)导出为XML
            Hashtable dataProject = DBProject.LoadProject(id);         

            string fileName = Path.GetFileNameWithoutExtension(Convert.ToString(dataProject["Name"])) + "_" + DateTime.Now.ToString("yyyyMMddHHmmss")+".";
            string fileType = Request["type"];
            if (string.IsNullOrEmpty(fileType))
            {
                fileType = "xml";
            }
            fileName += fileType;
            string filePath = HttpContext.Current.Server.MapPath(@"~/Upload/" + fileName);                       

            PluSoft.Utils.PlusProject.Write(filePath, dataProject);

            //2)下载XML
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.WriteFile(filePath);

            Response.Flush();
            FileInfo file = new FileInfo(filePath);
            file.Delete();

            Response.End();
        }
        else
        {
            Response.Write("请传入正确的项目UID");
        }
    }
开发者ID:linxueyang,项目名称:GTT,代码行数:35,代码来源:ExportProject.aspx.cs

示例15: DeleteFile

 public static void DeleteFile(string fileName)
 {
     FileInfo file = new FileInfo(fileName);
     if (file.Exists)
     {
         file.Delete();
     }
 }
开发者ID:jxzly229190,项目名称:OnlineStore,代码行数:8,代码来源:HomeController.cs


注:本文中的FileInfo.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。