網站安裝打包 建立網站[四][檔案解壓] 上

來源:互聯網
上載者:User

在建立網站之前,就是要把打包好的項目拷貝一份到IIS指定的路徑上,同時,還要為個別目錄設定相應的存取權限!

於是就產生了兩件事:

1。拷貝-》[這裡我是採用RAR打包,然後解壓]

2。設定許可權

如果是用拷貝方式,關於檔案夾Copy,可以參考我的這篇文章:

檔案夾複製操作(非遞迴迴圈遍曆檔案夾)

http://www.cnblogs.com/cyq1162/archive/2007/05/28/762294.html

 

 

為什麼我沒採用拷貝的方法,前提有兩個,就是項目的檔案夾有太多,在製作應用程式安裝程式時,只能添加檔案,而檔案夾只能一個一個的建立,太麻煩!要不就要把專案檔放到其它工程裡,那通過項目主輸出來實現。我也不想放到新工程或整合到工具項目裡,麻煩!

於是,我通過壓縮專案檔,當然沒有壓縮web.config,因為web.config是要修改的,在壓縮包裡就改不了。所以最後的做法是解壓RAR+檔案拷貝web.config!

關於RAR解壓,這裡給出一段代碼就算解決了:

 

RAR解壓

public bool WARToFoler(string rarFromPath, string rarToPath)
        {
            Process rarPro = new Process();
            rarPro.StartInfo.FileName = AppConfig.SoftSetup_WinRARSystemPath;
            rarPro.StartInfo.Arguments = string.Format(" x  \"{0}\" \"{1}\" -o+ -r -ibck", rarFromPath, rarToPath);
            rarPro.StartInfo.UseShellExecute = false;
            rarPro.StartInfo.RedirectStandardInput = true;
            rarPro.StartInfo.RedirectStandardOutput = true;
            rarPro.StartInfo.RedirectStandardError = true;
            rarPro.StartInfo.CreateNoWindow = true;
            rarPro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            rarPro.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_OutputDataReceived);
            rarPro.ErrorDataReceived += new DataReceivedEventHandler(rarPro_ErrorDataReceived);
            rarPro.Start();//解壓開始  
            rarPro.BeginOutputReadLine();
            rarPro.BeginErrorReadLine();
            rarPro.WaitForExit();
            rarPro.Dispose();
            return IsOK;
        }
        void rarPro_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data!=null && e.Data != "")
            {
                outMsg.Text += "失敗:" + e.Data + "\r\n";
                IsOK = false;
            }
        }
        void p_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
        {
            if (e.Data != null && e.Data != "")
            {
                outMsg.Text+="成功:" + e.Data + "\r\n";
            }
        }

 

AppConfig.SoftSetup_WinRARSystemPath這個是就是安裝的RAR.exe路徑!

-ibck參數是讓解壓在後台運行,這樣可以不用彈出個解壓框!

前些天也寫過一篇和RAR相關的文章:

記錄下關於調用RAR解壓縮的問題

http://www.cnblogs.com/cyq1162/archive/2010/01/13/1646678.html

OK,RAR解壓就這麼告一段落,接下來,我有一個App_Data目錄,由於會往裡面寫產生的xml,所以為之添加一個可寫入權限!

 

設定許可權的方式有三種,一種用net內建的封裝類。另一種直接調用cacls.exe實現,還有一種就是網上下的調用Microsoft.win32的某種複雜方式。

以下就用第一種了。用net內建的類實現,非常的簡單,三行代碼:

 

設定許可權

System.Security.AccessControl.DirectorySecurity fSec = new DirectorySecurity();
fSec.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
System.IO.Directory.SetAccessControl(path, fSec);

 

這裡是添加了一個everyone使用者,當然也可以換成aspnet使用者,具體看安全性要求給了!後面就給出了所有許可權。

具體關於許可權的說明,多百google度或在vs下看按F1協助文檔就清楚了!

 

打完,收工!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.