Overblog Suivre ce blog
Administration Créer mon blog

Présentation

  • : Romagny13 - Du .NET,du pur .NET
  • Romagny13 - Du .NET,du pur .NET
  • : Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions
  • Contact

Recherche

Articles Récents

21 juin 2007 4 21 /06 /juin /2007 10:30
[ OpenXml ]  – Créer un document Word 2007 (package) comprenant tous les fichiers et relations à partir de rien
 
J’utilise ici beaucoup LoadXml mais,d’autres posts sur OpenXml devraient arriver car je développe un outil pour justement mieux gérer ce format
   
private System.IO.Packaging.Package _Package;
 
        public System.IO.Packaging.Package Package
        {
            get { return _Package; }
            set { _Package = value; }
        }
 
#region create package
 
        public void CreateWordPackage(string PackageName)
        {
            Package = System.IO.Packaging.Package.Open(PackageName, System.IO.FileMode.Create);
            CreatedocPropsAppPackagePart();
            CreatedocPropsCorePackagePart();
            CreateWordDocumentPackagePart();
            CreateWordstylesPackagePart(); // 1
            CreateWordsettingsPackagePart(); // 2
            CreateWordwebSettingsPackagePart(); // 3
            CreateWordfonttablePackagePart(); // 4
            CreateWordthemestheme1PackagePart(); //5
        }
 
        #endregion
 
        #region docProps
 
        public void CreatedocPropsAppPackagePart()
        {
            System.IO.Packaging.PackagePart oPackagePart = Package.CreatePart(new Uri("/docProps/app.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.extended-properties+xml");
            CreateDocument(oPackagePart, @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><Properties xmlns=""http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"" xmlns:vt=""http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes""><Template>Normal.dotm</Template><TotalTime>0</TotalTime><Pages>1</Pages><Words>0</Words><Characters>0</Characters><Application>Microsoft Office Word</Application><DocSecurity>0</DocSecurity><Lines>1</Lines><Paragraphs>1</Paragraphs><ScaleCrop>false</ScaleCrop><Company></Company><LinksUpToDate>false</LinksUpToDate><CharactersWithSpaces>0</CharactersWithSpaces><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>12.0000</AppVersion></Properties>");
            Package.CreateRelationship(new Uri("docProps/app.xml", UriKind.Relative), System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties");
        }
        public void CreatedocPropsCorePackagePart()
        {
            System.IO.Packaging.PackagePart oPackagePart = Package.CreatePart(new Uri("/docProps/core.xml", UriKind.Relative), "application/vnd.openxmlformats-package.core-properties+xml");
            CreateDocument(oPackagePart, @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><cp:coreProperties xmlns:cp=""http://schemas.openxmlformats.org/package/2006/metadata/core-properties"" xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:dcterms=""http://purl.org/dc/terms/"" xmlns:dcmitype=""http://purl.org/dc/dcmitype/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><dc:title></dc:title><dc:subject></dc:subject><dc:creator>romagny</dc:creator><cp:keywords></cp:keywords><dc:description></dc:description><cp:lastModifiedBy>romagny</cp:lastModifiedBy><cp:revision>1</cp:revision><dcterms:created xsi:type=""dcterms:W3CDTF"">2007-06-21T07:32:00Z</dcterms:created><dcterms:modified xsi:type=""dcterms:W3CDTF"">2007-06-21T07:32:00Z</dcterms:modified></cp:coreProperties>");
            Package.CreateRelationship(new Uri("docProps/core.xml", UriKind.Relative), System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties");
        }
 
        #endregion docProps
 
        #region word
 
        public void CreateWordDocumentPackagePart()
        {
            System.IO.Packaging.PackagePart oPackagePart = Package.CreatePart(new Uri("/word/document.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
            CreateDocument(oPackagePart, @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><w:document xmlns:ve=""http://schemas.openxmlformats.org/markup-compatibility/2006"" 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:wp=""http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"" xmlns:w10=""urn:schemas-microsoft-com:office:word"" xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main"" xmlns:wne=""http://schemas.microsoft.com/office/word/2006/wordml""><w:body><w:p w:rsidR=""001A5467"" w:rsidRDefault=""001A5467"" /><w:sectPr w:rsidR=""001A5467"" w:rsidSect=""001A5467""><w:pgSz w:w=""11906"" w:h=""16838"" /><w:pgMar w:top=""1417"" w:right=""1417"" w:bottom=""1417"" w:left=""1417"" w:header=""708"" w:footer=""708"" w:gutter=""0"" /><w:cols w:space=""708"" /><w:docGrid w:linePitch=""360"" /></w:sectPr></w:body></w:document>");
            Package.CreateRelationship(new Uri("word/document.xml", UriKind.Relative), System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
        }
        public void CreateWordstylesPackagePart()
        {
            System.IO.Packaging.PackagePart oPackagePart = Package.CreatePart(new Uri("/word/styles.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml");
            CreateDocument(oPackagePart, @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><w:styles xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships"" xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""><w:docDefaults><w:rPrDefault><w:rPr><w:rFonts w:asciiTheme=""minorHAnsi"" w:eastAsiaTheme=""minorHAnsi"" w:hAnsiTheme=""minorHAnsi"" w:cstheme=""minorBidi""/><w:sz w:val=""22""/><w:szCs w:val=""22""/><w:lang w:val=""fr-FR"" w:eastAsia=""en-US"" w:bidi=""ar-SA""/></w:rPr></w:rPrDefault><w:pPrDefault><w:pPr><w:spacing w:after=""200"" w:line=""276"" w:lineRule=""auto""/></w:pPr></w:pPrDefault></w:docDefaults><w:latentStyles w:defLockedState=""0"" w:defUIPriority=""99"" w:defSemiHidden=""1"" w:defUnhideWhenUsed=""1"" w:defQFormat=""0"" w:count=""267""><w:lsdException w:name=""Normal"" w:semiHidden=""0"" w:uiPriority=""0"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""heading 1"" w:semiHidden=""0"" w:uiPriority=""9"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""heading 2"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""heading 3"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""heading 4"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""heading 5"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""heading 6"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""heading 7"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""heading 8"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""heading 9"" w:uiPriority=""9"" w:qFormat=""1""/><w:lsdException w:name=""toc 1"" w:uiPriority=""39""/><w:lsdException w:name=""toc 2"" w:uiPriority=""39""/><w:lsdException w:name=""toc 3"" w:uiPriority=""39""/><w:lsdException w:name=""toc 4"" w:uiPriority=""39""/><w:lsdException w:name=""toc 5"" w:uiPriority=""39""/><w:lsdException w:name=""toc 6"" w:uiPriority=""39""/><w:lsdException w:name=""toc 7"" w:uiPriority=""39""/><w:lsdException w:name=""toc 8"" w:uiPriority=""39""/><w:lsdException w:name=""toc 9"" w:uiPriority=""39""/><w:lsdException w:name=""caption"" w:uiPriority=""35"" w:qFormat=""1""/><w:lsdException w:name=""Title"" w:semiHidden=""0"" w:uiPriority=""10"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Default Paragraph Font"" w:uiPriority=""1""/><w:lsdException w:name=""Subtitle"" w:semiHidden=""0"" w:uiPriority=""11"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Strong"" w:semiHidden=""0"" w:uiPriority=""22"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Emphasis"" w:semiHidden=""0"" w:uiPriority=""20"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Table Grid"" w:semiHidden=""0"" w:uiPriority=""59"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Placeholder Text"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""No Spacing"" w:semiHidden=""0"" w:uiPriority=""1"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Light Shading"" w:semiHidden=""0"" w:uiPriority=""60"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light List"" w:semiHidden=""0"" w:uiPriority=""61"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Grid"" w:semiHidden=""0"" w:uiPriority=""62"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 1"" w:semiHidden=""0"" w:uiPriority=""63"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 2"" w:semiHidden=""0"" w:uiPriority=""64"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 1"" w:semiHidden=""0"" w:uiPriority=""65"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 2"" w:semiHidden=""0"" w:uiPriority=""66"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 1"" w:semiHidden=""0"" w:uiPriority=""67"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 2"" w:semiHidden=""0"" w:uiPriority=""68"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 3"" w:semiHidden=""0"" w:uiPriority=""69"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Dark List"" w:semiHidden=""0"" w:uiPriority=""70"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Shading"" w:semiHidden=""0"" w:uiPriority=""71"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful List"" w:semiHidden=""0"" w:uiPriority=""72"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Grid"" w:semiHidden=""0"" w:uiPriority=""73"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Shading Accent 1"" w:semiHidden=""0"" w:uiPriority=""60"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light List Accent 1"" w:semiHidden=""0"" w:uiPriority=""61"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Grid Accent 1"" w:semiHidden=""0"" w:uiPriority=""62"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 1 Accent 1"" w:semiHidden=""0"" w:uiPriority=""63"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 2 Accent 1"" w:semiHidden=""0"" w:uiPriority=""64"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 1 Accent 1"" w:semiHidden=""0"" w:uiPriority=""65"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Revision"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""List Paragraph"" w:semiHidden=""0"" w:uiPriority=""34"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Quote"" w:semiHidden=""0"" w:uiPriority=""29"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Intense Quote"" w:semiHidden=""0"" w:uiPriority=""30"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Medium List 2 Accent 1"" w:semiHidden=""0"" w:uiPriority=""66"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 1 Accent 1"" w:semiHidden=""0"" w:uiPriority=""67"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 2 Accent 1"" w:semiHidden=""0"" w:uiPriority=""68"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 3 Accent 1"" w:semiHidden=""0"" w:uiPriority=""69"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Dark List Accent 1"" w:semiHidden=""0"" w:uiPriority=""70"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Shading Accent 1"" w:semiHidden=""0"" w:uiPriority=""71"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful List Accent 1"" w:semiHidden=""0"" w:uiPriority=""72"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Grid Accent 1"" w:semiHidden=""0"" w:uiPriority=""73"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Shading Accent 2"" w:semiHidden=""0"" w:uiPriority=""60"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light List Accent 2"" w:semiHidden=""0"" w:uiPriority=""61"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Grid Accent 2"" w:semiHidden=""0"" w:uiPriority=""62"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 1 Accent 2"" w:semiHidden=""0"" w:uiPriority=""63"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 2 Accent 2"" w:semiHidden=""0"" w:uiPriority=""64"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 1 Accent 2"" w:semiHidden=""0"" w:uiPriority=""65"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 2 Accent 2"" w:semiHidden=""0"" w:uiPriority=""66"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 1 Accent 2"" w:semiHidden=""0"" w:uiPriority=""67"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 2 Accent 2"" w:semiHidden=""0"" w:uiPriority=""68"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 3 Accent 2"" w:semiHidden=""0"" w:uiPriority=""69"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Dark List Accent 2"" w:semiHidden=""0"" w:uiPriority=""70"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Shading Accent 2"" w:semiHidden=""0"" w:uiPriority=""71"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful List Accent 2"" w:semiHidden=""0"" w:uiPriority=""72"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Grid Accent 2"" w:semiHidden=""0"" w:uiPriority=""73"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Shading Accent 3"" w:semiHidden=""0"" w:uiPriority=""60"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light List Accent 3"" w:semiHidden=""0"" w:uiPriority=""61"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Grid Accent 3"" w:semiHidden=""0"" w:uiPriority=""62"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 1 Accent 3"" w:semiHidden=""0"" w:uiPriority=""63"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 2 Accent 3"" w:semiHidden=""0"" w:uiPriority=""64"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 1 Accent 3"" w:semiHidden=""0"" w:uiPriority=""65"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 2 Accent 3"" w:semiHidden=""0"" w:uiPriority=""66"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 1 Accent 3"" w:semiHidden=""0"" w:uiPriority=""67"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 2 Accent 3"" w:semiHidden=""0"" w:uiPriority=""68"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 3 Accent 3"" w:semiHidden=""0"" w:uiPriority=""69"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Dark List Accent 3"" w:semiHidden=""0"" w:uiPriority=""70"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Shading Accent 3"" w:semiHidden=""0"" w:uiPriority=""71"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful List Accent 3"" w:semiHidden=""0"" w:uiPriority=""72"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Grid Accent 3"" w:semiHidden=""0"" w:uiPriority=""73"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Shading Accent 4"" w:semiHidden=""0"" w:uiPriority=""60"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light List Accent 4"" w:semiHidden=""0"" w:uiPriority=""61"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Grid Accent 4"" w:semiHidden=""0"" w:uiPriority=""62"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 1 Accent 4"" w:semiHidden=""0"" w:uiPriority=""63"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 2 Accent 4"" w:semiHidden=""0"" w:uiPriority=""64"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 1 Accent 4"" w:semiHidden=""0"" w:uiPriority=""65"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 2 Accent 4"" w:semiHidden=""0"" w:uiPriority=""66"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 1 Accent 4"" w:semiHidden=""0"" w:uiPriority=""67"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 2 Accent 4"" w:semiHidden=""0"" w:uiPriority=""68"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 3 Accent 4"" w:semiHidden=""0"" w:uiPriority=""69"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Dark List Accent 4"" w:semiHidden=""0"" w:uiPriority=""70"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Shading Accent 4"" w:semiHidden=""0"" w:uiPriority=""71"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful List Accent 4"" w:semiHidden=""0"" w:uiPriority=""72"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Grid Accent 4"" w:semiHidden=""0"" w:uiPriority=""73"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Shading Accent 5"" w:semiHidden=""0"" w:uiPriority=""60"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light List Accent 5"" w:semiHidden=""0"" w:uiPriority=""61"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Grid Accent 5"" w:semiHidden=""0"" w:uiPriority=""62"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 1 Accent 5"" w:semiHidden=""0"" w:uiPriority=""63"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 2 Accent 5"" w:semiHidden=""0"" w:uiPriority=""64"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 1 Accent 5"" w:semiHidden=""0"" w:uiPriority=""65"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 2 Accent 5"" w:semiHidden=""0"" w:uiPriority=""66"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 1 Accent 5"" w:semiHidden=""0"" w:uiPriority=""67"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 2 Accent 5"" w:semiHidden=""0"" w:uiPriority=""68"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 3 Accent 5"" w:semiHidden=""0"" w:uiPriority=""69"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Dark List Accent 5"" w:semiHidden=""0"" w:uiPriority=""70"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Shading Accent 5"" w:semiHidden=""0"" w:uiPriority=""71"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful List Accent 5"" w:semiHidden=""0"" w:uiPriority=""72"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Grid Accent 5"" w:semiHidden=""0"" w:uiPriority=""73"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Shading Accent 6"" w:semiHidden=""0"" w:uiPriority=""60"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light List Accent 6"" w:semiHidden=""0"" w:uiPriority=""61"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Light Grid Accent 6"" w:semiHidden=""0"" w:uiPriority=""62"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 1 Accent 6"" w:semiHidden=""0"" w:uiPriority=""63"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Shading 2 Accent 6"" w:semiHidden=""0"" w:uiPriority=""64"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 1 Accent 6"" w:semiHidden=""0"" w:uiPriority=""65"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium List 2 Accent 6"" w:semiHidden=""0"" w:uiPriority=""66"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 1 Accent 6"" w:semiHidden=""0"" w:uiPriority=""67"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 2 Accent 6"" w:semiHidden=""0"" w:uiPriority=""68"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Medium Grid 3 Accent 6"" w:semiHidden=""0"" w:uiPriority=""69"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Dark List Accent 6"" w:semiHidden=""0"" w:uiPriority=""70"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Shading Accent 6"" w:semiHidden=""0"" w:uiPriority=""71"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful List Accent 6"" w:semiHidden=""0"" w:uiPriority=""72"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Colorful Grid Accent 6"" w:semiHidden=""0"" w:uiPriority=""73"" w:unhideWhenUsed=""0""/><w:lsdException w:name=""Subtle Emphasis"" w:semiHidden=""0"" w:uiPriority=""19"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Intense Emphasis"" w:semiHidden=""0"" w:uiPriority=""21"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Subtle Reference"" w:semiHidden=""0"" w:uiPriority=""31"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Intense Reference"" w:semiHidden=""0"" w:uiPriority=""32"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Book Title"" w:semiHidden=""0"" w:uiPriority=""33"" w:unhideWhenUsed=""0"" w:qFormat=""1""/><w:lsdException w:name=""Bibliography"" w:uiPriority=""37""/><w:lsdException w:name=""TOC Heading"" w:uiPriority=""39"" w:qFormat=""1""/></w:latentStyles><w:style w:type=""paragraph"" w:default=""1"" w:styleId=""Normal""><w:name w:val=""Normal""/><w:qFormat/><w:rsid w:val=""00934EB5""/></w:style><w:style w:type=""character"" w:default=""1"" w:styleId=""Policepardfaut""><w:name w:val=""Default Paragraph Font""/><w:uiPriority w:val=""1""/><w:semiHidden/><w:unhideWhenUsed/></w:style><w:style w:type=""table"" w:default=""1"" w:styleId=""TableauNormal""><w:name w:val=""Normal Table""/><w:uiPriority w:val=""99""/><w:semiHidden/><w:unhideWhenUsed/><w:qFormat/><w:tblPr><w:tblInd w:w=""0"" w:type=""dxa""/><w:tblCellMar><w:top w:w=""0"" w:type=""dxa""/><w:left w:w=""108"" w:type=""dxa""/><w:bottom w:w=""0"" w:type=""dxa""/><w:right w:w=""108"" w:type=""dxa""/></w:tblCellMar></w:tblPr></w:style><w:style w:type=""numbering"" w:default=""1"" w:styleId=""Aucuneliste""><w:name w:val=""No List""/><w:uiPriority w:val=""99""/><w:semiHidden/><w:unhideWhenUsed/></w:style></w:styles>");
            System.IO.Packaging.PackagePart DocumentRels = Package.GetPart(new Uri("/word/document.xml", UriKind.Relative));
            DocumentRels.CreateRelationship(new Uri("styles.xml", UriKind.Relative), System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles");
        }
        public void CreateWordsettingsPackagePart()
        {
            System.IO.Packaging.PackagePart oPackagePart = Package.CreatePart(new Uri("/word/settings.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml");
            CreateDocument(oPackagePart, @"<?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=""708""/><w:hyphenationZone w:val=""425""/><w:characterSpacingControl w:val=""doNotCompress""/><w:compat/><w:rsids><w:rsidRoot w:val=""00A918D7""/><w:rsid w:val=""00934EB5""/><w:rsid w:val=""00A918D7""/></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=""fr-FR""/><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>");
            System.IO.Packaging.PackagePart DocumentRels = Package.GetPart(new Uri("/word/document.xml", UriKind.Relative));
            DocumentRels.CreateRelationship(new Uri("settings.xml", UriKind.Relative), System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings");
        }
        public void CreateWordwebSettingsPackagePart()
        {
            System.IO.Packaging.PackagePart oPackagePart = Package.CreatePart(new Uri("/word/webSettings.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml");
            CreateDocument(oPackagePart, @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><w:webSettings xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships"" xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""><w:optimizeForBrowser/></w:webSettings>");
            System.IO.Packaging.PackagePart DocumentRels = Package.GetPart(new Uri("/word/document.xml", UriKind.Relative));
            DocumentRels.CreateRelationship(new Uri("webSettings.xml", UriKind.Relative), System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings");
        }
        public void CreateWordfonttablePackagePart()
        {
            System.IO.Packaging.PackagePart oPackagePart = Package.CreatePart(new Uri("/word/fontTable.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml");
            CreateDocument(oPackagePart, @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><w:fonts xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships"" xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""><w:font w:name=""Calibri""><w:panose1 w:val=""020F0502020204030204"" /><w:charset w:val=""00"" /><w:family w:val=""swiss"" /><w:pitch w:val=""variable"" /><w:sig w:usb0=""A00002EF"" w:usb1=""4000207B"" w:usb2=""00000000"" w:usb3=""00000000"" w:csb0=""0000009F"" w:csb1=""00000000"" /></w:font><w:font w:name=""Times New Roman""><w:panose1 w:val=""02020603050405020304"" /><w:charset w:val=""00"" /><w:family w:val=""roman"" /><w:pitch w:val=""variable"" /><w:sig w:usb0=""20002A87"" w:usb1=""80000000"" w:usb2=""00000008"" w:usb3=""00000000"" w:csb0=""000001FF"" w:csb1=""00000000"" /></w:font><w:font w:name=""Cambria""><w:panose1 w:val=""02040503050406030204"" /><w:charset w:val=""00"" /><w:family w:val=""roman"" /><w:pitch w:val=""variable"" /><w:sig w:usb0=""A00002EF"" w:usb1=""4000004B"" w:usb2=""00000000"" w:usb3=""00000000"" w:csb0=""0000009F"" w:csb1=""00000000"" /></w:font></w:fonts>");
            System.IO.Packaging.PackagePart DocumentRels = Package.GetPart(new Uri("/word/document.xml", UriKind.Relative));
            DocumentRels.CreateRelationship(new Uri("fontTable.xml", UriKind.Relative), System.IO.Packaging.TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable");
        }
Repost 0
Published by Romagny13 - dans Office
commenter cet article
16 juin 2007 6 16 /06 /juin /2007 20:57
[Linq To SQL ] – Astuce
Tracer les requêtes SQL exécutées
Très intéressant cela montre la requête SQL executée, et QUAND celle-ci l’est, dans mon exemple ce n’est qu’à la ligne > dataGridView1.DataSource = oContactCategories;
Que la requête est éxécutée
1 – avec la fenêtre Output (sortie)
Ajouter (db étant ici le DataContext)
db.Log = Console.Out;
 
Exemple
ContactDataContext db = new ContactDataContext();
           
            db.Log = Console.Out;
 
            System.Data.Linq.Table<ContactCategory> oContactCategories = db.GetTable<ContactCategory>();
 
            dataGridView1.DataSource = oContactCategories;
 
log1-copie-1.JPG
2 – Avec SQL Server Profiler
A condition bien entendu de disposer de SQL Server 2005 et non pas d’une version Express
log2.JPG
Repost 0
Published by Romagny13 - dans Linq To SQL
commenter cet article
15 juin 2007 5 15 /06 /juin /2007 20:15
Attributs personnalisés
Dans mon exemple je vais simuler un attribut personnalisé de Mapping comme le fait Linq To SQL
1 – Créer une classe pour cet attribut personnalisé
celle-ci doit hériter de System.Attribute
[AttributeUsage(AttributeTargets.Property,AllowMultiple=false)]
public class MappingAttribute : System.Attribute
    {
        private string _Storage;
 
        public string Storage
        {
            get { return _Storage; }
            set { _Storage = value; }
        }
 
        private string _Name;
 
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
 
 
        private bool _isPrimaryKey;
 
        public bool IsPrimaryKey
        {
            get { return _isPrimaryKey; }
            set { _isPrimaryKey = value; }
        }
 
        private bool _CanBeNull;
 
        public bool CanBeNull
        {
            get { return _CanBeNull; }
            set { _CanBeNull = value; }
        }
 
        private string _DBType;
 
        public string DBType
        {
            get { return _DBType; }
            set { _DBType = value; }
        }
 
        public MappingAttribute()
        { }
        public MappingAttribute(string Storage, string Name, bool IsPrimaryKey, bool CanBeNull, string DBType)
        {
            this.Storage = Storage;
            this.Name = Name;
            this.IsPrimaryKey = IsPrimaryKey;
            this.CanBeNull = CanBeNull;
            this.DBType = DBType;
        }
 
 
2 – Utilisation de l’attribut personnalisé que je viens de créer
public class Contact
    {
        private string _ContactName;
 
        [MappingAttribute(Storage = "ContactName", Name = "Name", DBType = "CHAR(150)", IsPrimaryKey = false, CanBeNull = false)]
        public string ContactName
        {
            get { return _ContactName; }
            set { _ContactName = value; }
        }
 
        public Contact()
        { }
        public Contact(string ContactName)
        {
            this.ContactName = ContactName;
        }
    }
 
3 – Récupérer les informations grâce à la reflection durant l’exécution du programme
private void button1_Click(object sender, EventArgs e)
        {
            Contact oContact = new Contact("Romagny");
 
            MessageBox.Show(GetMappingAttributeOfProperty("ContactName").Name);
        }
 
        public MappingAttribute GetMappingAttributeOfProperty(string PropertyName)
        {
            MappingAttribute oMappingAttribute = null;
            System.Reflection.Assembly oAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            foreach(Type oType in oAssembly.GetTypes())
            {
                if (oType.Name == "Contact")
                {
                    foreach (System.Reflection.PropertyInfo oPropertyInfo in oType.GetProperties())
                    {
                        if (oPropertyInfo.Name == PropertyName)
                        {
                            object[] CustomAttributes = oPropertyInfo.GetCustomAttributes(typeof(MappingAttribute), true);
                            oMappingAttribute = CustomAttributes[0] as MappingAttribute;
                        }
                    }
                }
            }
            return oMappingAttribute;
        } 
  
// OU plus rapide
 public MappingAttribute GetMappingAttributeOfProperty(string PropertyName)
        {
            System.Reflection.Assembly oAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            return oAssembly.GetType("AttributsPersonnalises.Contact").GetProperty(PropertyName).GetCustomAttributes(typeof(MappingAttribute), true)[0] as MappingAttribute;
        }
 
Repost 0
Published by Romagny13 - dans C 1.0- 2.0- 3.0
commenter cet article
10 juin 2007 7 10 /06 /juin /2007 15:49
Drag and Drop depuis l’explorateur de fichiers Windows vers son application
 
2 méthodes qui pourront être appelées par n’importe quel control depuis leurs évènements DragEnter et DragDrop
       public string[] DropFiles;
 
        private void GetDropFiles(DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                DropFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
                e.Effect = System.Windows.Forms.DragDropEffects.Move;
            }
        }
        private string GetDropFile(int Index)
        {
            string DropFile = string.Empty;
 
            if (DropFiles.Length == 0 || DropFiles.Length - 1 < Index)
            { }
            else
                DropFile = DropFiles[Index];
 
            return DropFile;
        }
 
Exemple d’utilisation avec une treeview (de la même manière cela pourrait être une listbox ou même la form en elle – même)
> ne pas oublier de mettre la propriété AllowDrop à true pour le control recevant le drag drop
        private void treeView1_DragEnter(object sender, DragEventArgs e)
        {
            GetDropFiles(e);
        }
 
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                string DropFile = GetDropFile(0);
                if (!string.IsNullOrEmpty(DropFile))
                    LoadFromFile.BeginInvoke(DropFile, null, null);
            }
            catch
            { }
        }
 
Repost 0
Published by Romagny13 - dans C 1.0- 2.0- 3.0
commenter cet article
8 juin 2007 5 08 /06 /juin /2007 20:09
Créer une dll afin d’améliorer les performances de traitement d’une expression régulière
Pour une application (éditeur avec coloration syntaxique) j’essaie de trouver tout ce qui me permettrait de gagner en performance, et notamment au chargement de fichier de taille conséquente (5000 lignes)
Dernière tentative en date > compilation d’une dll contenant la regex à utiliser, il parait que l’on peut gagner la moitié de temps en performance .. bof je ne l’ai pas encore verifié 
            string Keywords = @"(?<=s|{|}|(|)|,|=|^)(ABSOLUTE|ACTION|ADD|ALL|ALLOCATE|ALTER|AND|ANY|ARE|AS|ASC|ASSERTION|AT|AUTHORIZATION|AVG|BEGIN|BETWEEN|BIT|BIT_LENGTH|BOTH|BY|CASCADE|CASCADED|CASE|CAST|CATALOG|CHAR|CHARACTER|CHAR_LENGTH|CHARACTER_LENGTH|CHECK|CLOSE|COALESCE|COLLATE|COLLATION|COLUMN|COMMIT|CONNECT|CONNECTION|CONSTRAINT|CONSTRAINTS|CONTINUE|CONVERT|CORRESPONDING|COUNT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATE|DAY|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFERRABLE|DEFERRED|DELETE|DESC|DESCRIBE|DESCRIPTOR|DIAGNOSTICS|DISCONNECT|DISTINCT|DOMAIN|DOUBLE|DROP|ELSE|END|END-EXEC|ESCAPE|EXCEPT|EXCEPTION|EXEC|EXECUTE|EXISTS|EXTERNAL|EXTRACT|FALSE|FETCH|FIRST|FLOAT|FOR|FOREIGN|FOUND|FROM|FULL|GET|GLOBAL|GO|GOTO|GRANT|GROUP|HAVING|HOUR|IDENTITY|IMMEDIATE|IF|IN|INDICATOR|INITIALLY|INNER|INPUT|INSENSITIVE|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|IS|ISOLATION|JOIN|KEY|LANGUAGE|LAST|LEADING|LEFT|LEVEL|LIKE|LOCAL|LOWER|MATCH|MAX|MIN|MINUTE|MODULE|MONTH|NAMES|NATIONAL|NATURAL|NCHAR|NEXT|NO|NOT|NULL|NULLIF|NUMERIC|OCTET_LENGTH|OF|ON|ONLY|OPEN|OPTION|OR|ORDER|OUTER|OUTPUT|OVERLAPS|PAD|PARTIAL|POSITION|PRECISION|PREPARE|PRESERVE|PRIMARY|PRIOR|PRIVILEGES|PROCEDURE|PUBLIC|READ|REAL|REFERENCES|RELATIVE|RESTRICT|REVOKE|RIGHT|ROLLBACK|ROWS|SCHEMA|SCROLL|SECOND|SECTION|SELECT|SESSION|SESSION_USER|SET|SIZE|SMALLINT|SOME|SPACE|SQL|SQLCODE|SQLERROR|SQLSTATE|SUBSTRING|SUM|SYSTEM_USER|TABLE|TEMPORARY|THEN|TIME|TIMESTAMP|TIMEZONE_HOUR|TIMEZONE_MINUTE|TO|TRAILING|TRANSACTION|TRANSLATE|TRANSLATION|TRIM|TRUE|UNION|UNIQUE|UNKNOWN|UPDATE|UPPER|USAGE|USER|USING|VALUE|VALUES|VARCHAR|VARYING|VIEW|WHEN|WHENEVER|WHERE|WITH|WORK|WRITE|YEAR|ZONE)b";
            System.Text.RegularExpressions.RegexCompilationInfo oRegexCompilationInfo = new System.Text.RegularExpressions.RegexCompilationInfo(Keywords, System.Text.RegularExpressions.RegexOptions.IgnoreCase, "SQLEditorRegex", "SQLEditorRegex", true);
            System.Text.RegularExpressions.RegexCompilationInfo[] oRegexCompilationInfos = new System.Text.RegularExpressions.RegexCompilationInfo[] { oRegexCompilationInfo };
            System.Reflection.AssemblyName oAssemblyName = new System.Reflection.AssemblyName();
            oAssemblyName.Name = "Regex";
            System.Text.RegularExpressions.Regex.CompileToAssembly(oRegexCompilationInfos, oAssemblyName);
 
Une dll lest donc créée, il suffit ensuite de faire appel à celle-ci, le code généré dans la dll est plus que conséquent
compilationregex.JPG
Utilisation  :
SQLEditorRegex.SQLEditorRegex oSQLEditorRegex;
 
           oSQLEditorRegex=new SQLEditorRegex.SQLEditorRegex();
 
// etc.
 
public void ColorLine(int offset, string sCurrentLine)
        {
            if (!this.Created)
            { }
            else
            {
                Int32 endpos = offset + sCurrentLine.Length;
                tom.ITextRange rg = this.ITextDocument.Range(offset, endpos);
                if (rg.Font.CanChange() != 0)
                {
                    rg.Font.ForeColor = ColorToRGB(System.Drawing.Color.Black);
                    rg.Font.BackColor = 16777215;
                }
                System.Collections.IEnumerator oEnum = oSQLEditorRegex.Matches(sCurrentLine).GetEnumerator();
                while (oEnum.MoveNext())
                {
                    System.Text.RegularExpressions.Match oMatch = (System.Text.RegularExpressions.Match)oEnum.Current;
                    rg.SetRange(offset + oMatch.Index, offset + oMatch.Index + oMatch.Length);
                    rg.Font.BackColor = 16777215;
                    rg.Font.ForeColor = ColorToRGB(System.Drawing.Color.Blue);
                }
            }
        }
 
 
Bon je ne suis encore satisfait, car avec un gros fichier à traiter, il me faut bien 5 à 10 secondes
Repost 0
Published by Romagny13 - dans C 1.0- 2.0- 3.0
commenter cet article
28 mai 2007 1 28 /05 /mai /2007 21:32
Classe de sérialization générique
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Cs2PredicateHelper
{
    ///<summary>
    /// Classe de sérialization générique
    ///</summary>
    ///<typeparam name="T">Type générique</typeparam>
    public class SerializeManager<T>
    {
        public static void Serialize(T obj,string Path)
        {
            System.Xml.Serialization.XmlSerializer oXmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
            System.IO.StreamWriter oStreamWriter = new System.IO.StreamWriter(Path);
            oXmlSerializer.Serialize(oStreamWriter, obj);
            oStreamWriter.Close();
        }
        public static T Deserialize(string Path)
        {
            System.Xml.Serialization.XmlSerializer oXmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
            System.IO.StreamReader oStreamReader = new System.IO.StreamReader(Path);
            T obj = (T)oXmlSerializer.Deserialize(oStreamReader);
            oStreamReader.Close();
            return obj;
        }
    }
}
 
Utilisation
           // Serialization
            SerializeManager<List<Contact>>.Serialize(oContacts, "c:/test.xml");
 
            // Deserialization
           List<Contact> c= SerializeManager<List<Contact>>.Deserialize("c:/test.xml");
           dataGridView1.DataSource = c;
 
Repost 0
Published by Romagny13 - dans C 1.0- 2.0- 3.0
commenter cet article
26 mai 2007 6 26 /05 /mai /2007 10:20
Se connecter à un classeur Excel 2007 (*.xlsx) via ADO.NET
La chaine de connexion a la forme :
-          Provider=Microsoft.ACE.OLEDB.12.0;
-          Data Source=chemin complet vers le fichier Excel
-          Extended Properties=""Excel 12.0;HDR=YES;"""
private void button2_Click(object sender, EventArgs e)
        {
            System.Data.DataTable oDataTable = new DataTable();
            System.Data.OleDb.OleDbDataAdapter oOleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter();
            oOleDbDataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand();
            oOleDbDataAdapter.SelectCommand.Connection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:Documents and SettingsromagnyMes documentsDIVERS.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""");
            oOleDbDataAdapter.SelectCommand.CommandType = CommandType.Text;
            oOleDbDataAdapter.SelectCommand.CommandText = "SELECT [ContactID],[ContactName],[ContactFirstName],[ContactEmail],[ContactCategoryID] FROM [Contact$]";
 
            oOleDbDataAdapter.Fill(oDataTable);
 
            dataGridView1.DataSource = oDataTable;
        }

http://www.connectionstrings.com/default.aspx?carrier=excel2007
Repost 0
Published by Romagny13 - dans ADO.NET
commenter cet article
24 mai 2007 4 24 /05 /mai /2007 23:55
NHibernate - Expressions
NHibernate n’est pas parfait, je pense qu’il rajoute de la complexité inutilement
Notamment au niveau de  la gestion des connexions, trop complexe pour ce qu’elle est,
d’un autre côté NHibernate dispose quand même de pas mal de qualités(une fois son utilisation mieux maitrisée), par exemple le mapping est fait par fichier Xml
Nhibernate dispose également d’un système de requêtage qui ressemble un peu à ce que l’on peut faire avec Linq
On peut ajouter des critères de sélection « en cascade » , des tris …
Ex :
Je sélectionne tous les contacts de la table contact pour un ContactCategoryID(clé étrangère), et je trie sur ContactName, puis je fais appel à la méthode List() (oui cela ressemble vraiment à Linq ici) ce qui me retourne une liste
 private void button2_Click(object sender, EventArgs e)
        {
            ContactsHib.ContactDAO c = new ContactsHib.ContactDAO();
 
            System.Collections.IList List = c.MonCritere(Convert.ToInt32(comboBox1.Text));
 
            dataGridView1.DataSource = List;
        }
 
Dans ContactDAO je me crée une petite fonction
 public IList MonCritere(int ContactCategoryID)
        {
            ISession session = factory.OpenSession();
            IList List = session.CreateCriteria(typeof(ContactEntity))
           .Add(NHibernate.Expression.Expression.Eq("ContactCategoryID", ContactCategoryID))
           .AddOrder(Order.Desc("ContactName"))
           .List();
          
 
            return List;
        }
 
C’est un système de requetage interessant qui ressemble un peu à ce que  j’aimerais mettre en place dans un projet personnel
Repost 0
18 mai 2007 5 18 /05 /mai /2007 00:09
[ASP.NET 2.0] - Quelques utilisations du cache – chargement asynchrone avec SQL Server 2005
I - Mise en cache de la page :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Outputcache Duration="60" VaryByParam="none" %>
 
 
La page est mise en cache pour une minute ici
II - Mise en cache de données :
protected void Page_Load(object sender, EventArgs e)
    {
 
System.Data.OleDb.OleDbDataAdapter oOleDbDataAdapter = new                                      System.Data.OleDb.OleDbDataAdapter();
System.Data.DataTable oDataTable = new DataTable();
 
        try
        {
            if (Cache["ContactsKey"] == null)
            {
                oOleDbDataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand();
                oOleDbDataAdapter.SelectCommand.Connection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsromagnyMes documentsAccessContactsDb.mdb;");
                oOleDbDataAdapter.SelectCommand.CommandType = CommandType.Text;
                oOleDbDataAdapter.SelectCommand.CommandText = "SELECT * FROM Contact";
 
                oOleDbDataAdapter.SelectCommand.Connection.Open();
                oOleDbDataAdapter.Fill(oDataTable);
                Cache["ContactsKey"] = oDataTable;
            }
 
            GridView1.DataSource = Cache["ContactsKey"];
            GridView1.DataBind();
        }
        catch (System.SystemException ex)
        {
            //
            lblMessage.Text = ex.Message;
        }
        finally
        {
            if (oOleDbDataAdapter != null)
                if (oOleDbDataAdapter.SelectCommand != null)
                    if (oOleDbDataAdapter.SelectCommand.Connection.State == ConnectionState.Open)
                        oOleDbDataAdapter.SelectCommand.Connection.Close();
        }
 
    }
 
III - Avec cachedependency
1 er exemple : avec un fichier ici je « branche sur la base de données Acces, si des changemeents interviennent alors le cache concerné sera vidé
protected void Page_Load(object sender, EventArgs e)
    {
 
        System.Data.OleDb.OleDbDataAdapter oOleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter();
        System.Data.DataTable oDataTable = new DataTable();
 
        try
        {
            if (Cache["ContactsKey"] == null)
            {
                oOleDbDataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand();
                oOleDbDataAdapter.SelectCommand.Connection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsromagnyMes documentsAccessContactsDb.mdb;");
                oOleDbDataAdapter.SelectCommand.CommandType = CommandType.Text;
                oOleDbDataAdapter.SelectCommand.CommandText = "SELECT * FROM Contact";
 
                oOleDbDataAdapter.SelectCommand.Connection.Open();
                oOleDbDataAdapter.Fill(oDataTable);
                System.Web.Caching.CacheDependency oCacheDependency = new System.Web.Caching.CacheDependency(@"C:Documents and SettingsromagnyMes documentsAccessContactsDb.mdb");
 
                Cache.Insert("ContactsKey", oDataTable, oCacheDependency);
            }
 
            GridView1.DataSource = Cache["ContactsKey"];
            GridView1.DataBind();
        }
        catch (System.SystemException ex)
        {
            //
            lblMessage.Text = ex.Message;
        }
        finally
        {
            if (oOleDbDataAdapter != null)
                if (oOleDbDataAdapter.SelectCommand != null)
                    if (oOleDbDataAdapter.SelectCommand.Connection.State == ConnectionState.Open)
                        oOleDbDataAdapter.SelectCommand.Connection.Close();
        }
 
    }
 
2 eme exemple : avec SQL Server
A - Dans Web.config
<configuration>
      <appSettings/>
 <connectionStrings>
    <add name="ContactsDbConnectionString"
         connectionString="Data Source=.;Initial Catalog=ContactsDB;Integrated Security=SSPI;"
         providerName="System.Data.SqlClient"
         />
 </connectionStrings>
   
      <system.web>
    <caching>
      <sqlCacheDependency enabled="true">
        <databases>
          <add name="ContactsDbSqlConnection"
               connectionStringName="ContactsDbConnectionString"
               pollTime="500"
               />
        </databases>
      </sqlCacheDependency>
    </caching>
 
B – Attention il faut avoir activer la notification des tables grace à l’utilitaire aspnet_regsql.exe (C:/WINDOWS/Microsoft.NET/Frameworkv2.0.50727)
Ce qui donne quelque chose du style :
aspnet_regsql.exe –S DONJR –U sa –d ContactsDB -ed
Puis pour chaque table
aspnet_regsql.exe –S DONJR –U sa –d ContactsDB  -t Contact -et
-          DONJR > c’est le nom du serveur
-          sa > nom de l’utilisateur (ajouter le mot de passe avec –p)
-          ContactsDB > c’est la base de données
-          Contact > c’est le nom d’une des tables à activer
C - Code
protected void Page_Load(object sender, EventArgs e)
    {
 
System.Data.SqlClient.SqlDataAdapter oSqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter();
        System.Data.DataTable oDataTable = new DataTable();
 
        try
        {
            if (Cache["ContactsKeySql"] == null)
            {
                oSqlDataAdapter.SelectCommand = new System.Data.SqlClient.SqlCommand();
                oSqlDataAdapter.SelectCommand.Connection = new System.Data.SqlClient.SqlConnection(@"Data Source=.;Initial Catalog=ContactsDB;Integrated Security=SSPI;");
                oSqlDataAdapter.SelectCommand.CommandType = CommandType.Text;
                oSqlDataAdapter.SelectCommand.CommandText = "SELECT * FROM Contact";
 
                oSqlDataAdapter.SelectCommand.Connection.Open();
                oSqlDataAdapter.Fill(oDataTable);
 
                Cache.Insert("ContactsKeySql", oDataTable, new System.Web.Caching.SqlCacheDependency("ContactsDbSqlConnection", "Contact"));
            }
 
            GridView1.DataSource = Cache["ContactsKeySql"];
            GridView1.DataBind();
        }
        catch (System.SystemException ex)
        {
            //
            lblMessage.Text = ex.Message;
        }
        finally
        {
            if (oSqlDataAdapter != null)
                if (oSqlDataAdapter.SelectCommand != null)
                    if (oSqlDataAdapter.SelectCommand.Connection.State == ConnectionState.Open)
                        oSqlDataAdapter.SelectCommand.Connection.Close();
        }
}
 
IV - Chargement Asynchrone avec SQL Server
protected void Page_Load(object sender, EventArgs e)
    {
PageAsyncTask oPageAsyncTask = new PageAsyncTask(BeginInvokeMethod, EndInvokeMethod, EndTimeOutInvoke, null);
 
Page.RegisterAsyncTask(oPageAsyncTask);
    }
 
System.Data.SqlClient.SqlConnection oSqlConnection;
    System.Data.SqlClient.SqlCommand oSqlCommand;
 
    public IAsyncResult BeginInvokeMethod(object sender, EventArgs e, AsyncCallback callBack, object stateObject)
    {
        oSqlConnection = new System.Data.SqlClient.SqlConnection(@"async=true;Data Source=.;Initial Catalog=ContactsDB;Integrated Security=SSPI;");
        oSqlCommand = new System.Data.SqlClient.SqlCommand();
        oSqlCommand.Connection = oSqlConnection;
        oSqlCommand.CommandType = CommandType.Text;
        oSqlCommand.CommandText = "SELECT * FROM Contact";
 
        oSqlConnection.Open();
       return oSqlCommand.BeginExecuteReader(callBack, stateObject, CommandBehavior.CloseConnection);
    }
    public void EndInvokeMethod(IAsyncResult result)
    {
        System.Data.SqlClient.SqlDataReader oSqlDataReader = oSqlCommand.EndExecuteReader(result);
        if (oSqlDataReader != null)
        {
            GridView1.DataSource = oSqlDataReader;
            GridView1.DataBind();
        }
    }
    public void EndTimeOutInvoke(IAsyncResult result)
    {
        if (oSqlConnection != null)
            if (oSqlConnection.State == ConnectionState.Open)
                oSqlConnection.Close();
    }
 
Méthodes disponibles en asynchrone :
-          BeginExecuteNonQuery()
-          BeginExecuteReader()
-          BeginExecuteXmlReader()
+
-          EndExecuteNonQuery()
-          EndExecuteReader()
-          EndExecuteXmlReader()
 
Repost 0
Published by Romagny13 - dans ASP.NET
commenter cet article
17 mai 2007 4 17 /05 /mai /2007 21:19
Repost 0