2014-09-13 31 views
0

因此,我正在用C#編寫程序,我需要將我的項目中的文件添加到用戶系統上的文件夾中。從c#中的可執行文件中提取文件

我在Visual Studio 2013中的「解決方案資源管理器」中有一個文件夾,我希望這些文件以某種方式提取到用戶系統上的目錄中。

例如:

  1. 應用被執行。
  2. 應用程序從其內部提取文件到%APPDATA%/ MYFILES /文件

我是新的C#和學習的,所以請讓我知道這是否可行與否,如果有一個更好的方式去對這個。

在此先感謝。

+1

進一步的研究使我這個答案,工作: http://stackoverflow.com/a/2997157/3952266 – 2014-09-13 12:05:29

回答

0

在使用.NET 4.5的新類叫的ZipFile

您可以提取文件。

using System; 
    using System.IO; 
    using System.IO.Compression; 

namespace ConsoleApplication 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string startPath = @"c:\example\start"; 
      string zipPath = @"c:\example\result.zip"; 
      string extractPath = @"c:\example\extract"; 

      ZipFile.CreateFromDirectory(startPath, zipPath); 

      ZipFile.ExtractToDirectory(zipPath, extractPath); 
     } 
    } 
} 
+0

我可以擰,但是這只是從.zip文件中提取文件? – 2014-09-13 11:29:29

+0

向您展示了一個將在CreateFromDirectory的幫助下創建並在ExtractToDirectory的幫助下創建的示例。所以你需要調用ExtractToDirectory並給它一個正確的路徑,以便在zipPath變量中進行更改。 – codebased 2014-09-13 11:32:27

+0

那麼上面的方法會從可執行文件本身中提取文件嗎? – 2014-09-13 11:39:07

相關問題