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


C# FileInfo.Delete方法代码示例

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


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

示例1: ExportChart

    private void ExportChart(string fileName, ISymbolicDataAnalysisSolution solution, string formula) {
      FileInfo newFile = new FileInfo(fileName);
      if (newFile.Exists) {
        newFile.Delete();
        newFile = new FileInfo(fileName);
      }
      var formulaParts = formula.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

      using (ExcelPackage package = new ExcelPackage(newFile)) {
        ExcelWorksheet modelWorksheet = package.Workbook.Worksheets.Add("Model");
        FormatModelSheet(modelWorksheet, solution, formulaParts);

        ExcelWorksheet datasetWorksheet = package.Workbook.Worksheets.Add("Dataset");
        WriteDatasetToExcel(datasetWorksheet, solution.ProblemData);

        ExcelWorksheet inputsWorksheet = package.Workbook.Worksheets.Add("Inputs");
        WriteInputSheet(inputsWorksheet, datasetWorksheet, formulaParts.Skip(2), solution.ProblemData.Dataset);

        if (solution is IRegressionSolution) {
          ExcelWorksheet estimatedWorksheet = package.Workbook.Worksheets.Add("Estimated Values");
          WriteEstimatedWorksheet(estimatedWorksheet, datasetWorksheet, formulaParts, solution as IRegressionSolution);

          ExcelWorksheet chartsWorksheet = package.Workbook.Worksheets.Add("Charts");
          AddCharts(chartsWorksheet);
        }
        package.Workbook.Properties.Title = "Excel Export";
        package.Workbook.Properties.Author = "HEAL";
        package.Workbook.Properties.Comments = "Excel export of a symbolic data analysis solution from HeuristicLab";

        package.Save();
      }
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:32,代码来源:SymbolicSolutionExcelExporter.cs

示例2: SaveExcel

        /// <summary>
        /// 保存excel文件,覆盖相同文件名的文件
        /// </summary>
        public static void SaveExcel(string FileName, string sql, string SheetName)
        {

            FileInfo newFile = new FileInfo(FileName);
            if (newFile.Exists)
            {
                newFile.Delete();
                newFile = new FileInfo(FileName);
            }
            using (ExcelPackage package = new ExcelPackage(newFile))
            {
                try
                {
                    ExcelWorksheet ws = package.Workbook.Worksheets.Add(SheetName);

                    IDataReader reader = DBConfig.db.DBProvider.ExecuteReader(sql);
                    ws.Cells["A1"].LoadFromDataReader(reader, true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                package.Save();
            }
         
        }
开发者ID:hoku85,项目名称:DataPie,代码行数:29,代码来源:DBToExcel.cs

示例3: checksumPackage

            void checksumPackage(ReleaseEntry downloadedRelease)
            {
                var targetPackage = new FileInfo(
                    Path.Combine(rootAppDirectory, "packages", downloadedRelease.Filename));

                if (!targetPackage.Exists) {
                    this.Log().Error("File {0} should exist but doesn't", targetPackage.FullName);

                    throw new Exception("Checksummed file doesn't exist: " + targetPackage.FullName);
                }

                if (targetPackage.Length != downloadedRelease.Filesize) {
                    this.Log().Error("File Length should be {0}, is {1}", downloadedRelease.Filesize, targetPackage.Length);
                    targetPackage.Delete();

                    throw new Exception("Checksummed file size doesn't match: " + targetPackage.FullName);
                }

                using (var file = targetPackage.OpenRead()) {
                    var hash = Utility.CalculateStreamSHA1(file);

                    if (!hash.Equals(downloadedRelease.SHA1,StringComparison.OrdinalIgnoreCase)) {
                        this.Log().Error("File SHA1 should be {0}, is {1}", downloadedRelease.SHA1, hash);
                        targetPackage.Delete();
                        throw new Exception("Checksum doesn't match: " + targetPackage.FullName);
                    }
                }
            }
开发者ID:christianrondeau,项目名称:Squirrel.Windows.Next,代码行数:28,代码来源:UpdateManager.DownloadReleases.cs

示例4: ExtractResources

 private static void ExtractResources()
 {
     if (resourcesExtracted) {
         return;
     }
     lock (extractResourcesLock) {
         if (resourcesExtracted) {
             return;
         }
         var resourcesPath = GetAbsolutePath("Resources");
         var archives = Directory.EnumerateFiles(resourcesPath, "*.zip", SearchOption.AllDirectories);
         foreach (var archivePath in archives) {
             var destinationPath = Path.GetDirectoryName(archivePath);
             var archive = ZipFile.Open(archivePath, ZipArchiveMode.Read);
             foreach (var archiveEntry in archive.Entries) {
                 var fullEntryPath = Path.Combine(destinationPath, archiveEntry.FullName);
                 var fileInfo = new FileInfo(fullEntryPath);
                 if (fileInfo.Exists) {
                     if (fileInfo.Length != archiveEntry.Length) {
                         fileInfo.Delete();
                     } else if (fileInfo.LastWriteTimeUtc < archiveEntry.LastWriteTime.UtcDateTime) {
                         fileInfo.Delete();
                     }
                 }
                 if (!fileInfo.Exists) {
                     archiveEntry.ExtractToFile(fullEntryPath);
                 }
             }
         }
         resourcesExtracted = true;
     }
 }
开发者ID:nbalakin,项目名称:VSOutputEnhancer,代码行数:32,代码来源:Utils.cs

示例5: SyncServicePullFileTest

        public void SyncServicePullFileTest()
        {
            Device device = GetFirstDevice();
            FileListingService fileListingService = new FileListingService(device);

            using (ISyncService sync = device.SyncService)
            {
                String rfile = "/sdcard/bootanimations/bootanimation-cm.zip";
                FileEntry rentry = fileListingService.FindFileEntry(rfile);

                String lpath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                String lfile = Path.Combine(lpath, LinuxPath.GetFileName(rfile));
                FileInfo lfi = new FileInfo(lfile);
                SyncResult result = sync.PullFile(rfile, lfile, new FileSyncProgressMonitor());

                Assert.IsTrue(lfi.Exists);
                Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code));
                lfi.Delete();

                result = sync.PullFile(rentry, lfile, new FileSyncProgressMonitor());
                Assert.IsTrue(lfi.Exists);
                Assert.IsTrue(ErrorCodeHelper.RESULT_OK == result.Code, ErrorCodeHelper.ErrorCodeToString(result.Code));
                lfi.Delete();

            }
        }
开发者ID:phaufe,项目名称:madb,代码行数:26,代码来源:AdbHelperTests.cs

示例6: TestAssembly

        private TestAssembly(string assemblyName, string text, IEnumerable<string> referencePaths)
        {
            var path = new FileInfo(Path.Combine(System.IO.Path.GetTempPath(), assemblyName + ".exe"));
            _path = path.FullName;

            if (path.Exists)
            {
                // Don't regenerate if already created for this test run
                if (path.LastWriteTime < DateTime.Now.AddMinutes(-1))
                {
                    path.Delete();
                }
                else
                {
                    return;
                }
            }

            var references = referencePaths.Select(r => MetadataReference.CreateFromFile(r)).ToList();

            var tfm = CSharpSyntaxTree.ParseText(TFM);
            var tree = CSharpSyntaxTree.ParseText(text);
            var compilation = CSharpCompilation.Create(assemblyName, new[] { tree, tfm }, references);
            var result = compilation.Emit(path.FullName);

            if (!result.Success && path.Exists)
            {
                path.Delete();
            }

            Assert.True(result.Success, string.Join("\n", result.Diagnostics
                                                        .Where(d => d.Severity == DiagnosticSeverity.Error)
                                                        .Select(d => d.GetMessage())));
        }
开发者ID:vivmishra,项目名称:dotnet-apiport,代码行数:34,代码来源:TestAssembly.cs

示例7: CreateDeletePackage

        private static void CreateDeletePackage(int Sheets, int rows)
        {
            List<object> row = new List<object>();
            row.Add(1);
            row.Add("Some text");
            row.Add(12.0);
            row.Add("Some larger text that has completely no meaning.  How much wood can a wood chuck chuck if a wood chuck could chuck wood.  A wood chuck could chuck as much wood as a wood chuck could chuck wood.");

            FileInfo LocalFullFileName = new FileInfo(Path.GetTempFileName());
            LocalFullFileName.Delete();
            package = new ExcelPackage(LocalFullFileName);

            try
            {
                for (int ca = 0; ca < Sheets; ca++)
                {
                    CreateWorksheet("Sheet" + (ca+1), row, rows);
                }

                package.Save();
            }
            finally
            {
                LocalFullFileName.Refresh();
                if (LocalFullFileName.Exists)
                {
                    LocalFullFileName.Delete();
                }

                package.Dispose();
                package = null;

                GC.Collect();
            }
        }
开发者ID:acinep,项目名称:epplus,代码行数:35,代码来源:Program.cs

示例8: btnAggiornaDocumentiClick

        private void btnAggiornaDocumentiClick(object sender, EventArgs e)
        {
            var documenti = _daoFactory.GetDocumentoDao().GetAll();
            var aziende = _daoFactory.GetAziendaDao().GetAll();

            var documentFileSystemRespository = ConfigurationManager.AppSettings["fileSystemRepository"];
            foreach (var file in Directory.GetFiles(documentFileSystemRespository))
            {
                var fileInfo = new FileInfo(file);
                var checksum = Gipasoft.Library.Utility.GetFileChecksum(fileInfo);
                var documento = documenti.FirstOrDefault(item => item.Checksum == checksum);
                if(documento == null)
                    fileInfo.Delete();
                else
                {
                    var azienda = aziende.FirstOrDefault(item => item.ID == documento.Azienda.ID);
                    if (azienda != null)
                    {
                        var newPath = documentFileSystemRespository + azienda.Codice;
                        if(!string.IsNullOrEmpty(newPath))
                        {
                            if (!Directory.Exists(newPath))
                                Directory.CreateDirectory(newPath);
                            fileInfo.CopyTo(newPath + @"\" + fileInfo.Name);
                            fileInfo.Delete();
                        }
                    }
                    else
                        fileInfo.Delete();
                }
            }
        }
开发者ID:gipasoft,项目名称:Sfera,代码行数:32,代码来源:Form1.cs

示例9: ToImage

        public static FileInfo ToImage(string Html) {
            string wkhtmlPath = Path.Combine(HttpRuntime.AppDomainAppPath, "wkhtmltopdf");
            string svgPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Content", "svg");
            string uid = Guid.NewGuid().ToString();
            FileInfo htmlFi = new FileInfo(Path.Combine(svgPath, string.Format("{0}.html", uid)));
            FileInfo imageFi = new FileInfo(Path.Combine(svgPath, string.Format("{0}.svg", uid)));

            if (htmlFi.Exists) {
                htmlFi.Delete();
            }

            if (imageFi.Exists) {
                imageFi.Delete();
            }

            TextWriter twriter = new StreamWriter(htmlFi.FullName, false, Encoding.UTF8);
            twriter.Write(Html);
            twriter.Dispose();

            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
            psi.FileName = Path.Combine(wkhtmlPath, "wkhtmltoimage.exe");
            psi.Arguments = htmlFi.FullName + " " + imageFi.FullName;
            psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

            System.Diagnostics.Process.Start(psi).WaitForExit();
            htmlFi.Delete();

            return imageFi;
        }
开发者ID:miyconst,项目名称:MdToSvg,代码行数:29,代码来源:Converter.cs

示例10: Test

        /// <summary>
        /// Executes the tests.
        /// </summary>
        public static void Test()
        {
            TagsTableCollectionIndex index = new TagsTableCollectionIndex();

            // first fill the index.
            ITagCollectionIndexTests.FillIndex(index, 100000);

            // serialize the index.
            FileInfo testFile = new FileInfo(@"test.file");
            testFile.Delete();
            Stream writeStream = testFile.OpenWrite();
            OsmSharp.Logging.Log.TraceEvent("Blocked", System.Diagnostics.TraceEventType.Information,
                "Serializing blocked file....");
            TagIndexSerializer.SerializeBlocks(writeStream, index, 100);
            writeStream.Flush();
            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("Blocked", System.Diagnostics.TraceEventType.Information,
                string.Format("Serialized file: {0}KB", testFile.Length / 1024));

            // deserialize the index.
            Stream readStream = testFile.OpenRead();
            ITagsCollectionIndexReadonly readOnlyIndex = TagIndexSerializer.DeserializeBlocks(readStream);

            // test access.
            OsmSharp.Logging.Log.TraceEvent("Blocked", System.Diagnostics.TraceEventType.Information,
                "Started testing random access....");
            ITagCollectionIndexTests.TestRandomAccess("Blocked", readOnlyIndex, 1000);

            readStream.Dispose();
            testFile.Delete();
        }
开发者ID:vcotlearov,项目名称:OsmSharp,代码行数:35,代码来源:BlockedTagsCollectionIndexTests.cs

示例11: GenerateReport

        public static void GenerateReport(bool debugMode)
        {
            DataSet ds = DB.ExecuteStoredProcedure("sp_Report_CorporateInventory");
            string temporaryDirectory = @"C:\Temp";
            string temporaryFileName = string.Format("TrollbeadsInventory-{0:yyyMMdd}.csv", DateTime.Now);
            string temporaryFilePath = Path.Combine(temporaryDirectory, temporaryFileName);
            FileInfo fi = new FileInfo(temporaryFilePath);

            if (fi.Exists)
                fi.Delete();

            CsvExport myExport = new CsvExport();

            foreach(DataRow dr in ds.Tables[0].Rows)
            {
                myExport.AddRow();
                myExport["ProductNumber"] = dr["ProductNumber"];
                myExport["Description"] = dr["Description"];
                myExport["Category"] = dr["Category"];
                myExport["WholesalePrice"] = dr["WholesalePrice"];
                myExport["RetailPrice"] = dr["RetailPrice"];
                myExport["Quantity"] = dr["Quantity"];
            }

            myExport.ExportToFile(temporaryFilePath);

            if (!debugMode)
            {
                Email email = new Email();

                DataSet recipients = DB.ExecuteStoredProcedure("sp_Report_CorporateInventory_EmailRecipients");
                string to = string.Empty;
                string bcc = string.Empty;
                if (recipients != null && recipients.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in recipients.Tables[0].Rows)
                    {
                        string key = string.Format("{0}", row["Key"]);

                        if (key.Equals("reportCorporateInventoryRecipient", StringComparison.InvariantCultureIgnoreCase))
                            to = string.Format("{0}", row["Value"]);

                        if (key.Equals("reportCorporateInventoryRecipientBCC", StringComparison.InvariantCultureIgnoreCase))
                            bcc = string.Format("{0}", row["Value"]);
                    }
                }

                email.Send(to: to, cc: null, bcc: bcc, subject: "Trollbeads Inventory", body: string.Empty, filePathForAttachment: temporaryFilePath);

                fi.Delete();
            }
        }
开发者ID:benharrison,项目名称:tIMS,代码行数:52,代码来源:CorporateInventory.cs

示例12: Custom

 public static int Custom(string filename, string data, string pre_fix = null, bool overwrite = false)
 {
     int RetVal = 0;
     lock (_custom) {
         FileInfo fi = new FileInfo ("logs/" + filename);
         StreamWriter sw;
         try {
             if (!Directory.Exists("logs"))
                 Directory.CreateDirectory("logs");
             if (overwrite)
             {
                 fi.Delete();
                 sw = fi.CreateText();
             }
             else
             {
                 if (fi.Exists && !overwrite)
                 {
                     if (fi.Length > Log_Size_Limit)
                     {
                         fi.CopyTo("logs/" + filename + ".bak", true);
                         fi.Delete();
                     }
                 }
                 sw = fi.AppendText();
             }
             if (!fi.Exists)
             {
                 sw.WriteLine(DateTime.Now.ToString() + " - [0] - File Created");
             }
             if (pre_fix != null)
                 sw.WriteLine(pre_fix + DateTime.Now.ToString() + " - " + data);
             else
                 sw.WriteLine (DateTime.Now.ToString () + " - " + data);
             sw.Close ();
             sw.Dispose();
         } catch (UnauthorizedAccessException e) {
             NagiosExtentions.FileAgeCheck.debugOutput.Add("UnauthorizedAccessException caught in QuasarQode.logs: " + e.Message);
             RetVal = 1001;
         } catch (IOException e) {
             NagiosExtentions.FileAgeCheck.debugOutput.Add("IOException caught in QuasarQode.logs: " + e.Message);
             RetVal = 1002;
         }
         catch (Exception e)
         {
             NagiosExtentions.FileAgeCheck.debugOutput.Add("Generic Exception caught in QuasarQode.logs: " + e.Message);
             RetVal = 1003;
         }
     }
     return RetVal;
 }
开发者ID:kenjindomini,项目名称:Nagios_FileAge_Extention,代码行数:51,代码来源:Logging.cs

示例13: Create

        /// <summary>
        /// Creates a file from a list of strings; each string is placed on a line in the file.
        /// </summary>
        /// <param name="TempFileName">Name of response file</param>
        /// <param name="Lines">List of lines to write to the response file</param>
        public static string Create(string TempFileName, List<string> Lines)
        {
            FileInfo TempFileInfo = new FileInfo( TempFileName );
            DirectoryInfo TempFolderInfo = new DirectoryInfo( TempFileInfo.DirectoryName );

            // Delete the existing file if it exists
            if( TempFileInfo.Exists )
            {
                TempFileInfo.IsReadOnly = false;
                TempFileInfo.Delete();
                TempFileInfo.Refresh();
            }

            // Create the folder if it doesn't exist
            if( !TempFolderInfo.Exists )
            {
                // Create the
                TempFolderInfo.Create();
                TempFolderInfo.Refresh();
            }

            using( FileStream Writer = TempFileInfo.OpenWrite() )
            {
                using( StreamWriter TextWriter = new StreamWriter( Writer ) )
                {
                    Lines.ForEach( x => TextWriter.WriteLine( x ) );
                }
            }

            return TempFileName;
        }
开发者ID:Tigrouzen,项目名称:UnrealEngine-4,代码行数:36,代码来源:ResponseFile.cs

示例14: gdvFiles_Info_RowDeleting

    protected void gdvFiles_Info_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        OA.OAService service = new OA.OAService();
        OA.BoardModel model = new OA.BoardModel();
        model.BOARD_ID =int.Parse(gdvFiles.DataKeys[e.RowIndex].Value.ToString());

        DataSet ds = service.BBS_Board_Delete(model, strAccount);
        if (ds != null && ds.Tables.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string[] removes = dr["ATTACHMENT_ID"].ToString().Split('*');
                foreach (string strremove in removes)
                {
                    if (strremove != "")
                    {
                        System.IO.FileInfo info = new System.IO.FileInfo(Request.PhysicalApplicationPath + "\\Attachment\\BBS\\" + strremove);
                        info.Delete();
                    }
                }
            }
            Response.Write("<script>alert('删除成功!');</script>");
            DataBound();
        }
        else
            Response.Write("<script>alert('删除失败,请与管理员联系!');</script>");
    }
开发者ID:dalinhuang,项目名称:128Web,代码行数:27,代码来源:BoardManage.aspx.cs

示例15: CopyFile

        /// <summary>
        /// Copy the specified file.
        /// </summary>
        ///
        /// <param name="source">The file to copy.</param>
        /// <param name="target">The target of the copy.</param>
        public static void CopyFile(FileInfo source, FileInfo target)
        {
            try
            {
                var buffer = new byte[BufferSize];

                // open the files before the copy
                FileStream
                    ins0 = source.OpenRead();
                target.Delete();
                FileStream xout = target.OpenWrite();

                // perform the copy
                int packetSize = 0;

                while (packetSize != -1)
                {
                    packetSize = ins0.Read(buffer, 0, buffer.Length);
                    if (packetSize != -1)
                    {
                        xout.Write(buffer, 0, packetSize);
                    }
                }

                // close the files after the copy
                ins0.Close();
                xout.Close();
            }
            catch (IOException e)
            {
                throw new EncogError(e);
            }
        }
开发者ID:CreativelyMe,项目名称:encog-dotnet-core,代码行数:39,代码来源:Directory.cs


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