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


C# Package.PartExists方法代码示例

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


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

示例1: GetPackagePart

        private static PackagePart GetPackagePart(Package package, string partFilePath)
        {
            Uri packagePartUri = GetPackagePartUri(partFilePath);

            if (package.PartExists(packagePartUri))
                return package.GetPart(packagePartUri);
            else
                return null;
        }
开发者ID:kurthamilton,项目名称:Utilities,代码行数:9,代码来源:WorkbookCleaner.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: GetNewUri

 internal Uri GetNewUri(Package package, string sUri)
 {
     int id = 1;
     Uri uri;
     do
     {
         uri = new Uri(string.Format(sUri, id++), UriKind.Relative);
     }
     while (package.PartExists(uri));
     return uri;
 }
开发者ID:huoxudong125,项目名称:EPPlus,代码行数:11,代码来源:XmlHelper.cs

示例6: CertificatePart

        /// <summary>
        /// CertificatePart constructor
        /// </summary>
        internal CertificatePart(Package container, Uri partName)
        {
            if (container == null)
                throw new ArgumentNullException("container");
            
            if (partName == null)
                throw new ArgumentNullException("partName");

            partName = PackUriHelper.ValidatePartUri(partName);
            
            // create if not found
            if (container.PartExists(partName))
            {
                // open the part
                _part = container.GetPart(partName);

                // ensure the part is of the expected type
                if (_part.ValidatedContentType.AreTypeAndSubTypeEqual(_certificatePartContentType) == false)
                    throw new FileFormatException(SR.Get(SRID.CertificatePartContentTypeMismatch));
            }
            else
            {
                // create the part
                _part = container.CreatePart(partName, _certificatePartContentType.ToString());
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:29,代码来源:Certificate.cs

示例7: CreateOrGetSettingsPart

        internal static PackagePart CreateOrGetSettingsPart(Package package)
        {
            PackagePart settingsPart;

            Uri settingsUri = new Uri("/word/settings.xml", UriKind.Relative);
            if (!package.PartExists(settingsUri))
            {
                settingsPart = package.CreatePart(settingsUri, "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", CompressionOption.Maximum);

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

                mainDocumentPart.CreateRelationship(settingsUri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings");

                XDocument settings = XDocument.Parse
                (@"<?xml version='1.0' encoding='utf-8' standalone='yes'?>
                <w:settings xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' xmlns:m='http://schemas.openxmlformats.org/officeDocument/2006/math' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:w10='urn:schemas-microsoft-com:office:word' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' xmlns:sl='http://schemas.openxmlformats.org/schemaLibrary/2006/main'>
                  <w:zoom w:percent='100' />
                  <w:defaultTabStop w:val='720' />
                  <w:characterSpacingControl w:val='doNotCompress' />
                  <w:compat />
                  <w:rsids>
                    <w:rsidRoot w:val='00217F62' />
                    <w:rsid w:val='001915A3' />
                    <w:rsid w:val='00217F62' />
                    <w:rsid w:val='00A906D8' />
                    <w:rsid w:val='00AB5A74' />
                    <w:rsid w:val='00F071AE' />
                  </w:rsids>
                  <m:mathPr>
                    <m:mathFont m:val='Cambria Math' />
                    <m:brkBin m:val='before' />
                    <m:brkBinSub m:val='--' />
                    <m:smallFrac m:val='off' />
                    <m:dispDef />
                    <m:lMargin m:val='0' />
                    <m:rMargin m:val='0' />
                    <m:defJc m:val='centerGroup' />
                    <m:wrapIndent m:val='1440' />
                    <m:intLim m:val='subSup' />
                    <m:naryLim m:val='undOvr' />
                  </m:mathPr>
                  <w:themeFontLang w:val='en-IE' w:bidi='ar-SA' />
                  <w:clrSchemeMapping w:bg1='light1' w:t1='dark1' w:bg2='light2' w:t2='dark2' w:accent1='accent1' w:accent2='accent2' w:accent3='accent3' w:accent4='accent4' w:accent5='accent5' w:accent6='accent6' w:hyperlink='hyperlink' w:followedHyperlink='followedHyperlink' />
                  <w:shapeDefaults>
                    <o:shapedefaults v:ext='edit' spidmax='2050' />
                    <o:shapelayout v:ext='edit'>
                      <o:idmap v:ext='edit' data='1' />
                    </o:shapelayout>
                  </w:shapeDefaults>
                  <w:decimalSymbol w:val='.' />
                  <w:listSeparator w:val=',' />
                </w:settings>"
                );

                XElement themeFontLang = settings.Root.Element(XName.Get("themeFontLang", DocX.w.NamespaceName));
                themeFontLang.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), CultureInfo.CurrentCulture);

                // Save the settings document.
                using (TextWriter tw = new StreamWriter(settingsPart.GetStream()))
                    settings.Save(tw);
            }
            else
                settingsPart = package.GetPart(settingsUri);
            return settingsPart;
        }
开发者ID:algola,项目名称:backup,代码行数:66,代码来源:HelperFunctions.cs

示例8: Select

        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// This method returns the list of selected PackageRelationships as per the
        /// given criteria, from a part in the Package provided
        /// </summary>
        /// <param name="package">Package object from which we get the relationsips</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If package parameter is null</exception>
        public List<PackageRelationship> Select(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            List<PackageRelationship> relationships = new List<PackageRelationship>(0);

            switch (SelectorType)
            {
                case PackageRelationshipSelectorType.Id:
                    if (SourceUri.Equals(PackUriHelper.PackageRootUri))
                    {
                        if (package.RelationshipExists(SelectionCriteria))
                            relationships.Add(package.GetRelationship(SelectionCriteria));
                    }
                    else
                    {
                        if (package.PartExists(SourceUri))
                        {
                            PackagePart part = package.GetPart(SourceUri);
                            if (part.RelationshipExists(SelectionCriteria))
                                relationships.Add(part.GetRelationship(SelectionCriteria));
                        }
                    }
                    break;

                case PackageRelationshipSelectorType.Type:
                    if (SourceUri.Equals(PackUriHelper.PackageRootUri))
                    {
                        foreach (PackageRelationship r in package.GetRelationshipsByType(SelectionCriteria))
                            relationships.Add(r);
                    }
                    else
                    {
                        if (package.PartExists(SourceUri))
                        {
                            foreach (PackageRelationship r in package.GetPart(SourceUri).GetRelationshipsByType(SelectionCriteria))
                                relationships.Add(r);
                        }
                    }
                    break;

                default:
                    //Debug.Assert is fine here since the parameters have already been validated. And all the properties are 
                    //readonly
                    Debug.Assert(false, "This option should never be called");
                    break;
            }

            return relationships;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:68,代码来源:PackageRelationshipSelector.cs

示例9: 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

示例10: WriteMainDocument

        /// <summary>
        /// Writes the main document part of a CDDX file, and embeds components as required.
        /// </summary>
        /// <param name="package">The package to write to.</param>
        /// <param name="document">The document containing the metadata to write.</param>
        /// <param name="options">Options for saving.</param>
        void WriteMainDocument(Package package)
        {
            // Prevent EmbedComponents from being null
            if (EmbedComponents == null)
                EmbedComponents = new Dictionary<IOComponentType, EmbedComponentData>();

            // Create the main Document part
            Uri DocumentUri = PackUriHelper.CreatePartUri(new Uri("circuitdiagram\\Document.xml", UriKind.Relative));
            PackagePart DocumentPart = package.CreatePart(DocumentUri, ContentTypeNames.MainDocument, CompressionOption.Normal);
            package.CreateRelationship(DocumentPart.Uri, TargetMode.Internal, RelationshipTypes.Document);

            using (var stream = DocumentPart.GetStream(FileMode.Create))
            {
                XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("circuit", Namespaces.Document);
                writer.WriteAttributeString("version", String.Format("{0:0.0}", FormatVersion));
                writer.WriteAttributeString("xmlns", "r", null, Namespaces.Relationships);
                writer.WriteAttributeString("xmlns", "ec", null, Namespaces.DocumentComponentDescriptions);

                // Document size
                writer.WriteStartElement("properties");
                writer.WriteElementString("width", Document.Size.Width.ToString());
                writer.WriteElementString("height", Document.Size.Height.ToString());
                writer.WriteEndElement();

                // Component types
                int idCounter = 0; // generate IDs for each IOComponentType
                Dictionary<IOComponentType, int> typeIDs = new Dictionary<IOComponentType, int>(); // store IDs for use in <elements> section
                writer.WriteStartElement("definitions");
                foreach (KeyValuePair<string, List<IOComponentType>> collection in Document.GetComponentTypes())
                {
                    writer.WriteStartElement("src");

                    // Write the collection name if it is known
                    if (collection.Key != IODocument.UnknownCollection)
                        writer.WriteAttributeString("col", collection.Key);

                    foreach (IOComponentType item in collection.Value)
                    {
                        writer.WriteStartElement("add");
                        writer.WriteAttributeString("id", idCounter.ToString());

                        // Write the collection item if it belongs to a collection
                        if (collection.Key != IODocument.UnknownCollection)
                            writer.WriteAttributeString("item", item.Item);

                        // Write additional attributes for opening with the same component description
                        if (!String.IsNullOrEmpty(item.Name))
                            writer.WriteAttributeString("name", Namespaces.DocumentComponentDescriptions, item.Name);
                        if (item.GUID != Guid.Empty)
                            writer.WriteAttributeString("guid", Namespaces.DocumentComponentDescriptions, item.GUID.ToString());

                        // Write additional attributes for embedding
                        if (EmbedComponents.ContainsKey(item))
                        {
                            // Generate unique file name
                            Uri descriptionPath = PackUriHelper.CreatePartUri(new Uri("circuitdiagram/components/" + item.Name.Replace(' ', '_') + EmbedComponents[item].FileExtension, UriKind.Relative));
                            int addedInt = 0;
                            while (package.PartExists(descriptionPath))
                            {
                                descriptionPath = PackUriHelper.CreatePartUri(new Uri("circuitdiagram/components/" + item.Name.Replace(' ', '_') + addedInt.ToString() + ".cdcom", UriKind.Relative));
                                addedInt++;
                            }

                            // Write part
                            PackagePart descriptionPart = package.CreatePart(PackUriHelper.CreatePartUri(descriptionPath), EmbedComponents[item].ContentType, CompressionOption.Normal);
                            using (var descriptionStream = descriptionPart.GetStream(FileMode.Create))
                            {
                                // Copy stream
                                int num;
                                byte[] buffer = new byte[4096];
                                while ((num = EmbedComponents[item].Stream.Read(buffer, 0, buffer.Length)) != 0)
                                {
                                    descriptionStream.Write(buffer, 0, num);
                                }
                            }
                            PackageRelationship relationship = DocumentPart.CreateRelationship(descriptionPart.Uri, TargetMode.Internal, CDDX.RelationshipTypes.IncludedComponent);

                            // Write the relationship ID
                            writer.WriteAttributeString("id", Namespaces.Relationships, relationship.Id);

                            // Store the relationship ID for use later
                            EmbedComponents[item].Tag = relationship.Id;
                        }
                        else if (EmbedComponents.ContainsKey(item) && !EmbedComponents[item].IsEmbedded)
                        {
                            // Already embedded - write relationship ID
                            writer.WriteAttributeString("id", Namespaces.DocumentComponentDescriptions, EmbedComponents[item].Tag as string);
                        }

                        writer.WriteEndElement();

//.........这里部分代码省略.........
开发者ID:csuffyy,项目名称:circuitdiagram,代码行数:101,代码来源:CDDXWriter.cs

示例11: 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

示例12: 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

示例13: FromXmlReader

        public Card FromXmlReader(XmlReader reader, Game game, Set set, PackagePart definition, Package package)
        {
            var ret = new Card();
            var Properties = new SortedList<PropertyDef, object>(game.CustomProperties.Count());
            reader.MoveToAttribute("name");
            ret.Name = reader.Value;
            reader.MoveToAttribute("id");
            ret.Id = new Guid(reader.Value);
            //           isMutable = false;
            if (reader.MoveToAttribute("alternate"))
            {
                try { ret.Alternate = new Guid(reader.Value); }
                catch (Exception e)
                {
                    throw new ArgumentException(String.Format("The value {0} is not of expected type for property Alternate. Alternate must be a GUID.",
                                                reader.Value));
                }
            }
            else { ret.Alternate = System.Guid.Empty; }
            if (reader.MoveToAttribute("dependent"))
            {
                try
                {
                    ret.Dependent = new Guid(reader.Value).ToString();
                }
                catch
                {
                    try
                    {
                        ret.Dependent = Boolean.Parse(reader.Value).ToString();
                    }
                    catch
                    {

                        throw new ArgumentException(String.Format("The value {0} is not of expected type for property Dependent. Dependent must be either true/false, or the Guid of the card to use instead.",
                                                      reader.Value));
                    }
                }
            }
            else { ret.Dependent = String.Empty; }
            Uri cardImageUri = definition.GetRelationship("C" + ret.Id.ToString("N")).TargetUri;
            ret.ImageUri = cardImageUri.OriginalString;
            if (!package.PartExists(cardImageUri))
                throw new Exception(string.Format("Image for card '{0}', with URI '{1}' was not found in the package.",
                                                  ret.Name, ret.ImageUri));
            reader.Read(); // <card>

            while (reader.IsStartElement("property"))
            {
                reader.MoveToAttribute("name");
                PropertyDef prop = game.CustomProperties.FirstOrDefault(p => p.Name == reader.Value);
                if (prop == null)
                    throw new ArgumentException(string.Format("The property '{0}' is unknown", reader.Value));
                reader.MoveToAttribute("value");
                try
                {
                    switch (prop.Type)
                    {
                        case PropertyType.String:
                            Properties.Add(prop, reader.Value);
                            break;
                        case PropertyType.Integer:
                            Properties.Add(prop, Int32.Parse(reader.Value));
                            break;
                        case PropertyType.Char:
                            Properties.Add(prop, Char.Parse(reader.Value));
                            break;
                        default:
                            throw new NotImplementedException();
                    }
                }
                catch (FormatException)
                {
                    throw new ArgumentException(String.Format("The value {0} is not of expected type for property {1}",
                                                                reader.Value, prop.Name));
                }
                reader.Read(); // <property/>
            }
            ret.Properties = Properties;

            reader.Read(); // </card>
            return ret;
        }
开发者ID:voidbeast,项目名称:OCTGN,代码行数:83,代码来源:CardManager.cs


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