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


C# Package.CreatePart方法代码示例

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


在下文中一共展示了Package.CreatePart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ZipDirectory

        private void ZipDirectory(string SourceFolderPath, Package package,int deviceType)
        {
            DirectoryInfo dir = new DirectoryInfo(SourceFolderPath);
            FileInfo[] files=dir.GetFiles();
            foreach (FileInfo fi in files)
            {                
                if ((".tdb".Equals(fi.Extension, StringComparison.OrdinalIgnoreCase) && deviceType == 1) || (".dat".Equals(fi.Extension, StringComparison.OrdinalIgnoreCase) && deviceType == 2)
                    || (".doc".Equals(fi.Extension, StringComparison.OrdinalIgnoreCase) && deviceType == 2) || ".crd".Equals(fi.Extension, StringComparison.OrdinalIgnoreCase) || deviceType == 3)
                {
                    string relativePath = fi.FullName.Replace(SourceFolderPath, string.Empty);
                    relativePath = relativePath.Replace("\\", "/");
                    Uri partUriDocument = PackUriHelper.CreatePartUri(new Uri(relativePath, UriKind.Relative));

                    //resourcePath="Resource\Image.jpg"
                    //Uri partUriResource = PackUriHelper.CreatePartUri(new Uri(resourcePath, UriKind.Relative));

                    PackagePart part = package.CreatePart(partUriDocument, System.Net.Mime.MediaTypeNames.Application.Zip);
                    using (FileStream fs = fi.OpenRead())
                    {
                        using (Stream partStream = part.GetStream())
                        {
                            CopyStream(fs, partStream);
                            fs.Close();
                            partStream.Close();
                        }
                    }
                }                

            }
            DirectoryInfo[] directories = dir.GetDirectories();
            foreach (DirectoryInfo subDi in directories)
            {
                ZipDirectory(SourceFolderPath, package, deviceType);
            }
        }
开发者ID:mydipcom,项目名称:MEIKReport,代码行数:35,代码来源:ZipTools.cs

示例3: AddContent

        void AddContent(Package package, PackageDefinition manifest, Uri partUri, string file)
        {
            var part =
                    package.CreatePart(
                        PackUriHelper.CreatePartUri(partUri), System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);

                using (var partStream = part.GetStream())
                using (var fileStream = fileSystem.OpenFile(file, FileMode.Open))
                {
                    fileStream.CopyTo(partStream);
                    partStream.Flush();
                    fileStream.Position = 0;
                    var hashAlgorithm = new SHA256Managed();
                    hashAlgorithm.ComputeHash(fileStream);
                    manifest.Contents.Add(new ContentDefinition
                    {
                        Name = partUri.ToString(),
                        Description =
                            new ContentDescription
                            {
                                DataStorePath = partUri,
                                LengthInBytes = (int) fileStream.Length,
                                HashAlgorithm = IntegrityCheckHashAlgorithm.Sha256,
                                Hash = Convert.ToBase64String(hashAlgorithm.Hash)
                            }
                    });
                }
        }
开发者ID:sergio,项目名称:Calamari,代码行数:28,代码来源:RePackageCloudServiceConvention.cs

示例4: AddFile

 public static void AddFile(Package result,string baseFolder,string relativePath,CompressionOption compressionOption)
 {
     FileInfo f = new FileInfo(baseFolder+relativePath.Replace("/","\\"));
     //f.Extension;
     PackagePart data = result.CreatePart(new Uri(relativePath, UriKind.Relative), GetContentType(f.Name), compressionOption);
     StreamReader reader = new StreamReader(baseFolder+relativePath.Replace("/","\\"));
     WriteAll(data.GetStream(), reader.BaseStream);
     reader.Close();
 }
开发者ID:andreyu,项目名称:Reports,代码行数:9,代码来源:NoteCreator.cs

示例5: AddFileToPackage

 private static void AddFileToPackage(Package zip, string f)
 {
     PackagePart p = zip.CreatePart(
         PackUriHelper.CreatePartUri(new Uri(new FileInfo(f).Name, UriKind.RelativeOrAbsolute)), MediaTypeNames.Text.Plain);
     using (var fileStream = new FileStream(f, FileMode.Open, FileAccess.Read))
     {
         CopyStream(fileStream, p.GetStream());
         // zip.CreateRelationship(p.Uri, TargetMode.Internal, f);
     }
 }
开发者ID:PicNet,项目名称:closuresnippets,代码行数:10,代码来源:PackageSnippets.cs

示例6: CreatePart

 void CreatePart(Package package, string filePath, Stream sourceStream)
 {
     filePath = filePath.Replace(PackageDirectory, "").TrimStart('\\');
     var uri = PackUriHelper.CreatePartUri(new Uri(Uri.EscapeDataString(filePath), UriKind.Relative));
     var packagePart = package.CreatePart(uri, "application/octet", CompressionOption.Maximum);
     using (var stream = packagePart.GetStream())
     {
         sourceStream.CopyTo(stream);
     }
 }
开发者ID:SimonCropp,项目名称:Pepita,代码行数:10,代码来源:Runner.cs

示例7: CreatePart

        private static void CreatePart(Package package, string file, string contentType)
        {
            var part = package.CreatePart(
                new Uri("/" + file, UriKind.Relative), contentType);

            using (var fileStream = new FileStream(
                GetPath(PackagePath + file), FileMode.Open, FileAccess.Read)) {
                CopyStream(fileStream, part.GetStream());
            }
        }
开发者ID:e-llumin-net-ltd,项目名称:VFx,代码行数:10,代码来源:Packager.cs

示例8: AddPackageManifest

        void AddPackageManifest(Package package, PackageDefinition manifest)
        {
            var manifestPartUri = PackUriHelper.CreatePartUri(new Uri("/package.xml", UriKind.Relative));
            var manifestPart = package.CreatePart(manifestPartUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);
            using (var manifestPartStream = manifestPart.GetStream())
            {
                manifest.ToXml().Save(manifestPartStream);
            }

            package.CreateRelationship(manifestPartUri, TargetMode.External, AzureCloudServiceConventions.CtpFormatPackageDefinitionRelationshipType);
        }
开发者ID:bjewell52,项目名称:Calamari,代码行数:11,代码来源:RePackageCloudServiceConvention.cs

示例9: WriteCache

		private void WriteCache(Package package)
		{
			Uri cacheUri = GetPartUri(cacheName);
			PackagePart part = package.CreatePart(cacheUri, MediaTypeNames.Application.Octet, CompressionOption.Fast);

			BinaryFormatter formatter = new BinaryFormatter();
			using (Stream stream = part.GetStream())
			{
				formatter.Serialize(stream, Cache);
			}

			package.CreateRelationship(cacheUri, TargetMode.Internal, D3AssemblyConstants.DefaultXmlNamespace);
		}
开发者ID:elsiete,项目名称:DynamicDataDisplay,代码行数:13,代码来源:ZipFileTileServer.cs

示例10: CreatePart

 void CreatePart(Package package, string entry)
 {
     var filePath = entry.Replace(PackageDirectory, "").TrimStart('\\');
     var segments = filePath.Split(new[] { '/', Path.DirectorySeparatorChar }, StringSplitOptions.None)
                .Select(Uri.EscapeDataString);
     var escapedPath = String.Join("/", segments);
     var uri = PackUriHelper.CreatePartUri(new Uri(escapedPath, UriKind.Relative));
     var packagePart = package.CreatePart(uri, "application/octet", CompressionOption.Maximum);
     using (var inputFileStream = File.OpenRead(entry))
     using (var zipStream = packagePart.GetStream())
     {
         inputFileStream.CopyTo(zipStream);
     }
 }
开发者ID:SimonCropp,项目名称:Pepita,代码行数:14,代码来源:PartCreator.cs

示例11: WriteManifest

    static void WriteManifest(Package package, string nuspecPath)
    {
        var uri = PackUriHelper.CreatePartUri(new Uri(Uri.EscapeDataString(Path.GetFileName(nuspecPath)), UriKind.Relative));

        // Create the manifest relationship
        package.CreateRelationship(uri, TargetMode.Internal, "http://schemas.microsoft.com/packaging/2010/07/manifest");

        // Create the part
        var packagePart = package.CreatePart(uri, "application/octet", CompressionOption.Maximum);

        using (var stream = packagePart.GetStream())
        using (var fileStream = File.OpenRead(nuspecPath))
        {
            fileStream.CopyTo(stream);
        }
    }
开发者ID:SimonCropp,项目名称:Pepita,代码行数:16,代码来源:Runner.cs

示例12: ExportProcessPart

		private static void ExportProcessPart(Package package, WfProcessDescriptor processDesc, WfExportProcessDescriptorContext context)
		{
			Uri partUri = CreatePartUri(processDesc.Key, WfProcessDescriptorPackagePartType.ProcessPart);

			if (context.ExistingParts.Contains(partUri.ToString()))
				return;

			XElement xeWfProcess = context.Formatter.Serialize(processDesc);
			XDocument xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "true"), xeWfProcess);

			PackagePart part = package.CreatePart(partUri, MediaTypeNames.Text.Xml, CompressionOption.Normal);

			using (Stream stream = part.GetStream())
				xDoc.Save(stream);

			context.ExistingParts.Add(partUri.ToString());
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:17,代码来源:WfProcessDescriptorExporter.cs

示例13: AddDefaultNumberingXml

        /// <summary>
        /// If this document does not contain a /word/numbering.xml add the default one generated by Microsoft Word 
        /// when the default bullet, numbered and multilevel lists are added to a blank document
        /// </summary>
        /// <param name="package"></param>
        /// <param name="mainDocumentPart"></param>
        /// <returns></returns>
        internal static XDocument AddDefaultNumberingXml(Package package)
        {
            XDocument numberingDoc;
            // Create the main document part for this package
            PackagePart wordNumbering = package.CreatePart(new Uri("/word/numbering.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", CompressionOption.Maximum);

            numberingDoc = DecompressXMLResource("Novacode.Resources.numbering.xml.gz");

            // Save /word/numbering.xml
            using (TextWriter tw = new StreamWriter(wordNumbering.GetStream(FileMode.Create, FileAccess.Write)))
                numberingDoc.Save(tw, SaveOptions.None);

            PackagePart mainDocumentPart = package.GetParts().Single(p => p.ContentType.Equals(DOCUMENT_DOCUMENTTYPE, StringComparison.CurrentCultureIgnoreCase) ||
                                                                          p.ContentType.Equals(TEMPLATE_DOCUMENTTYPE, StringComparison.CurrentCultureIgnoreCase));

            mainDocumentPart.CreateRelationship(wordNumbering.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering");
            return numberingDoc;
        }
开发者ID:CPonty,项目名称:DocX,代码行数:25,代码来源:HelperFunctions.cs

示例14: CreateNewPart

        private static void CreateNewPart(PackagePart inputPart, Package outputPackage)
        {
            var contentType = IsObfuscatedFont(inputPart) ? "application/vnd.ms-opentype" : inputPart.ContentType;

            var outputPart = outputPackage.CreatePart(inputPart.Uri, contentType, CompressionOption.Normal);
            if (outputPart == null)
            {
                throw new ApplicationException("Couldn't create new part");
            }

            if (IsObfuscatedFont(inputPart))
            {
                CopyObfuscatedFontPart(inputPart, outputPart);
            }
            else
            {
                CopyPart(inputPart, outputPart);
            }
        }
开发者ID:tonyedgecombe,项目名称:Deinterleave,代码行数:19,代码来源:OPCCopier.cs

示例15: ZipDirectory

        private void ZipDirectory(DirectoryInfo di, Package package)
        {
            foreach (FileInfo fi in di.GetFiles())
            {
                string relativePath = fi.FullName.Replace(SourceFolderPath, string.Empty);
                relativePath = relativePath.Replace("\\", "/");
                PackagePart part = package.CreatePart(new Uri(relativePath, UriKind.Relative), System.Net.Mime.MediaTypeNames.Application.Zip);
                using (FileStream fs = fi.OpenRead())
                {
                    CopyStream(fs, part.GetStream());
                }

            }

            foreach (DirectoryInfo subDi in di.GetDirectories())
            {
                ZipDirectory(subDi, package);
            }
        }
开发者ID:GenealogyChina,项目名称:ToolSource,代码行数:19,代码来源:ZipManager.cs


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