天天看點

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

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

于是就産生了兩件事:

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

2。設定權限

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

檔案夾複制操作(非遞歸循環周遊檔案夾)

<a href="http://www.cnblogs.com/cyq1162/archive/2007/05/28/762294.html" target="_blank">http://www.cnblogs.com/cyq1162/archive/2007/05/28/762294.html</a>

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

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

關于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 &amp;&amp; e.data != "")

            {

                outmsg.text += "失敗:" + e.data + "\r\n";

                isok = false;

            }

        void p_outputdatareceived(object sender, system.diagnostics.datareceivedeventargs e)

            if (e.data != null &amp;&amp; e.data != "")

                outmsg.text+="成功:" + e.data + "\r\n";

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

appconfig.softsetup_winrarsystempath這個是就是安裝的rar.exe路徑!

-ibck參數是讓解壓在背景運作,這樣可以不用彈出個解壓框!

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

記錄下關于調用rar解壓縮的問題

<a href="http://www.cnblogs.com/cyq1162/archive/2010/01/13/1646678.html" target="_blank">http://www.cnblogs.com/cyq1162/archive/2010/01/13/1646678.html</a>

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幫助文檔就清楚了!

打完,收工!