System.IO.Packaging.Package.CreateRelationship C# (CSharp) Méthode

CreateRelationship() public méthode

public CreateRelationship ( Uri targetUri, TargetMode targetMode, string relationshipType ) : PackageRelationship
targetUri System.Uri
targetMode TargetMode
relationshipType string
Résultat PackageRelationship
        public PackageRelationship CreateRelationship(Uri targetUri, TargetMode targetMode, string relationshipType)
        {
            return CreateRelationship(targetUri, targetMode, relationshipType, null);
        }

Same methods

Package::CreateRelationship ( Uri targetUri, TargetMode targetMode, string relationshipType, string id ) : PackageRelationship
Package::CreateRelationship ( Uri targetUri, TargetMode targetMode, string relationshipType, string id, bool loading ) : PackageRelationship

Usage Example

Exemple #1
0
        /// <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);
            }
        }
All Usage Examples Of System.IO.Packaging.Package::CreateRelationship