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


C# Package.DeletePart方法代码示例

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


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

示例1: ExcelPackage

        /// <summary>
        /// Creates a new instance of the ExcelPackage class based on a existing file or creates a new file. 
        /// </summary>
        /// <param name="newFile">If newFile exists, it is opened.  Otherwise it is created from scratch.</param>
        private ExcelPackage(FileInfo newFile)
        {
            _outputFolderPath = newFile.DirectoryName;
            if (newFile.Exists)
            {
                // open the existing package
                _package = Package.Open(newFile.FullName, FileMode.Open, FileAccess.ReadWrite);
            }
            else
            {
                // create a new package and add the main workbook.xml part
                _package = Package.Open(newFile.FullName, FileMode.Create, FileAccess.ReadWrite);

                // save a temporary part to create the default application/xml content type
                var uriDefaultContentType = new Uri("/default.xml", UriKind.Relative);
                var partTemp = _package.CreatePart(uriDefaultContentType, "application/xml");

                var workbook = Workbook.WorkbookXml; // this will create the workbook xml in the package

                // create the relationship to the main part
                _package.CreateRelationship(Workbook.WorkbookUri,
                                            TargetMode.Internal,
                                            schemaRelationships + "/officeDocument");

                // remove the temporary part that created the default xml content type
                _package.DeletePart(uriDefaultContentType);
            }
        }
开发者ID:HedinRakot,项目名称:Zierer,代码行数:32,代码来源:ExcelPackage.cs

示例2: AddFileToPackage

 public static void AddFileToPackage(Package package, string uri, string filePath, string contentType)
 {
     FileInfo info = new FileInfo(filePath);
     uri = MakeUriSafe(uri);
     if (!info.Exists)
     {
         throw new FileNotFoundException(Strings.Package_FileCouldNotBeAdded, filePath);
     }
     Uri partUri = new Uri(uri, UriKind.Relative);
     string extension = info.Extension;
     if (package.PartExists(partUri))
     {
         package.DeletePart(partUri);
     }
     PackagePart part = package.CreatePart(partUri, contentType, CompressionOption.Maximum);
     using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
     {
         using (Stream stream2 = part.GetStream())
         {
             CopyStream(stream, stream2);
         }
         stream.Close();
     }
 }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:24,代码来源:PackageHelper.cs

示例3: RenamePath

 public static void RenamePath(Package package, string oldUri, string newUri)
 {
     Uri partUri = new Uri(oldUri, UriKind.Relative);
     Uri uri2 = new Uri(newUri, UriKind.Relative);
     if (package.PartExists(partUri))
     {
         PackagePart part = package.GetPart(partUri);
         PackagePart part2 = package.CreatePart(uri2, part.ContentType, part.CompressionOption);
         using (Stream stream = part.GetStream())
         {
             using (Stream stream2 = part2.GetStream())
             {
                 CopyStream(stream, stream2);
             }
         }
         package.DeletePart(partUri);
     }
 }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:18,代码来源:PackageHelper.cs

示例4: RemoveFileFromPackage

 public static void RemoveFileFromPackage(Package package, string uri)
 {
     Uri partUri = new Uri(uri, UriKind.Relative);
     if (package.PartExists(partUri))
     {
         package.DeletePart(partUri);
     }
 }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:8,代码来源:PackageHelper.cs

示例5: AddPart

 static void AddPart(Package zip, string root, string path) {
     Uri uri = PackUriHelper.CreatePartUri(new Uri(path, UriKind.Relative));
     if (zip.PartExists(uri)) {
         zip.DeletePart(uri);
     }
     PackagePart part = zip.CreatePart(uri, "", CompressionOption.Normal);
     using (FileStream fileStream = new FileStream(Path.Combine(root, path), FileMode.Open, FileAccess.Read)) {
         using (Stream dest = part.GetStream()) {
             CopyStream(fileStream, dest);
         }
     }
 }
开发者ID:Xarlot,项目名称:DXVcs2Git,代码行数:12,代码来源:Program.cs

示例6: StmCreatePart

        /* S T M  C R E A T E  P A R T */
        /*----------------------------------------------------------------------------
            %%Function: StmCreatePart
            %%Qualified: ArbWeb.OOXML.StmCreatePart
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public static Stream StmCreatePart(Package pkg, string sUri, string sContentType, out PackagePart prt)
        {
            Uri uriTeams = new System.Uri(sUri, UriKind.Relative);

            prt = pkg.GetPart(uriTeams);

            List<PackageRelationship> plrel = new List<PackageRelationship>();

            foreach (PackageRelationship rel in prt.GetRelationships())
                {
                plrel.Add(rel);
                }

            prt = null;

            pkg.DeletePart(uriTeams);
            prt = pkg.CreatePart(uriTeams, sContentType);

            foreach (PackageRelationship rel in plrel)
                {
                prt.CreateRelationship(rel.TargetUri, rel.TargetMode, rel.RelationshipType, rel.Id);
                }

            return prt.GetStream(FileMode.Create, FileAccess.Write);
        }
开发者ID:rlittletht,项目名称:ArbWeb,代码行数:32,代码来源:ooxml.cs

示例7: AddToArchive

 private static void AddToArchive(Package zip, string fileToAdd, string root)
 {
     try
     {
         string uriFileName = fileToAdd.Replace(" ", "_");
         FileAttributes attr = System.IO.File.GetAttributes(fileToAdd);
         if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
         {
             root = root + "/" + Path.GetFileName(uriFileName);
             string[] subfolders = Directory.GetDirectories(fileToAdd);
             for (int i = 0; i < subfolders.Length; i++)
             {
                 AddToArchive(zip, subfolders[i], root);
             }
             string[] subfiles = Directory.GetFiles(fileToAdd);
             for (int i = 0; i < subfiles.Length; i++)
             {
                 AddToArchive(zip, subfiles[i], root);
             }
         }
         else
         {
             string zipUri = string.Concat(root + "/", Path.GetFileName(uriFileName));
             Uri partUri = new Uri(zipUri, UriKind.Relative);
             string contentType = System.Net.Mime.MediaTypeNames.Application.Zip;
             if (zip.PartExists(partUri)) zip.DeletePart(partUri);
             PackagePart pkgPart = zip.CreatePart(partUri, contentType, CompressionOption.Normal);
             Byte[] bytes = System.IO.File.ReadAllBytes(fileToAdd);
             pkgPart.GetStream().Write(bytes, 0, bytes.Length);
         }
     }
     catch (Exception ex)
     {
         TextWindow.WriteLine(fileToAdd);
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
     }
 }
开发者ID:litdev1,项目名称:LitDev,代码行数:37,代码来源:Zip.cs

示例8: AddToArchive

        private bool AddToArchive(Package zip, string fileToAdd,Backup bck)
        {
            // Replace spaces with an underscore (_)
            string uriFileName = fileToAdd.Replace(" ", "_");

            // A Uri always starts with a forward slash "/"
            string zipUri = string.Concat("/", Path.GetFileName(uriFileName));

            Uri partUri = new Uri(zipUri, UriKind.Relative);
            string contentType = MediaTypeNames.Application.Zip;

            if (!zip.PartExists(partUri))
            {
                zip.DeletePart(partUri);
            }
            if (!zip.PartExists(partUri))
            {
                PackagePart pkgPart = zip.CreatePart(partUri, contentType, ConvertCompIntoCompressOption(bck.compressLevel));

                // Read all of the bytes from the file to add to the zip file
                Byte[] bites = null;

                if (bck.isVss)
                {
                    MessageBox.Show(sShadowPath + fileToAdd);
                    //bites = wApi.GetFileData(sShadowPath + Path.GetFileName(fileToAdd));
                }
                else
                {
                    try
                    {
                        bites = File.ReadAllBytes(fileToAdd);
                    }
                    catch (Exception e)
                    {
                        bites = null;
                    }
                }

                //Compress and write the bytes to the zip file

                if (bites != null)
                {

                    pkgPart.GetStream().Write(bites, 0, bites.Length);
                    return true;
                }
                else
                    return false;

            }
            else
                return false;
        }
开发者ID:Habupain,项目名称:UniBackup,代码行数:54,代码来源:ZipManager.cs


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