检测使用Iconic zip提取前的文件

时间:2014-07-28 08:24:26

标签: c# asp.net xml

我使用Iconic.zip作为在服务器上提取文件的方法,但是它用于主题包。我希望能够在解压缩之前检查zip文件中是否存在文件。

我正在使用以下代码来上传和解压缩文件。

      if (fileUploadZipFiles.HasFile)
        {
            string uploadedZipFile = Path.GetFileName(fileUploadZipFiles.PostedFile.FileName);
            string zipFileLocation = Server.MapPath("~/Themes/" + uploadedZipFile);
            fileUploadZipFiles.SaveAs(zipFileLocation);

            ZipFile zipFileToExtract = ZipFile.Read(zipFileLocation);
            zipFileToExtract.ExtractAll(Server.MapPath("~/Themes/" + txtFolderName.Text.ToString()), ExtractExistingFileAction.DoNotOverwrite);
            gridviewExtractedFiles.DataSource = zipFileToExtract.Entries;
            gridviewExtractedFiles.DataBind();
            lblMessage.Text = "Zip file extracted successfully and containes following files";
        }

这个问题的第二部分是我在主题中使用母版页如何将活动主题设置为用户想要激活的主题。我相信我必须拥有自己的基页。

我发现问题的第一部分是使用以下内容。

  if (fileUploadZipFiles.HasFile)
        {
            string uploadedZipFile = Path.GetFileName(fileUploadZipFiles.PostedFile.FileName);
            string zipFileLocation = Server.MapPath("~/Themes/" + uploadedZipFile);
            fileUploadZipFiles.SaveAs(zipFileLocation);

            ZipFile zipFileToExtract = ZipFile.Read(zipFileLocation);
                var result = zipFileToExtract.Any(entry => entry.FileName.EndsWith("site.master"));
                if (result == true)
                {

                    zipFileToExtract.ExtractAll(Server.MapPath("~/Themes/" + txtFolderName.Text.ToString()), ExtractExistingFileAction.DoNotOverwrite);
                    gridviewExtractedFiles.DataSource = zipFileToExtract.Entries;
                    gridviewExtractedFiles.DataBind();
                    lblMessage.Text = "Zip file extracted successfully and containes following files";
                }
                else 
                    lblMessage.Text = "Not a vlaid theme file.";

        }

正如这里建议的那样,我使用linq来检查文件是否存在。

  protected void btnExtractZipFiles_Click(object sender, EventArgs e)
    {
        if (txtFolderName.Text == "")
        {
            lblMessage.Text = "A Folder Name must be specified";
        }else

        if (fileUploadZipFiles.HasFile)
        {

            string uploadedZipFile = Path.GetFileName(fileUploadZipFiles.PostedFile.FileName);
            string zipFileLocation = Server.MapPath("~/Themes/" + uploadedZipFile);
            fileUploadZipFiles.SaveAs(zipFileLocation);

            ZipFile zipFileToExtract = ZipFile.Read(zipFileLocation);
            var result = zipFileToExtract.Any(entry => entry.FileName.EndsWith("default.Master"));
                if (result == true)
                {

                    zipFileToExtract.ExtractAll(Server.MapPath("~/Themes/" + txtFolderName.Text.ToString()), ExtractExistingFileAction.DoNotOverwrite);
                    gridviewExtractedFiles.DataSource = zipFileToExtract.Entries;
                    gridviewExtractedFiles.DataBind();
                    lblMessage.Text = "Zip file extracted successfully and containes following files";
                    SetConfiguration(); //parse the configuration file
                }
                else 
                    lblMessage.Text = "Not a vlaid theme file.";

        }

    }

0 个答案:

没有答案