Meilleur auteur de réponses
Erreur System.Security.Permissions.FileIOPermission

Question
-
Bonjour
Voila mon problème, j'utilise une dll pour créer des Document word a partir d'un code c#.
Pour l'instant je n'avais pas de problème jusqu'a ce que j'inclue des images
Voila mon code :
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.High)] [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.High)] // [System.Security.Permissions.FileIOPermission(SecurityAction.InheritanceDemand, AspNetHostingPermissionLevel.High)] class MyDocument { public MyDocument(SPWorkflowActivationProperties workflowProperties) { // Create a new document. using (SPSite mySite = SPContext.Current.Site) { // Open a connection to the SharePoint site using (SPWeb Web = mySite.OpenWeb()) { // Grab a document stored on this site SPFile file = Web.GetFile("Template/DMF.docx"); // Create a MemoryStream ms. MemoryStream str = new MemoryStream(file.OpenBinary()); using (FileStream fs = new FileStream(@"C:\Users\cbureau\Desktop\WorkflowSharePoint\Word-RF-DMF\Word-RF-DMF\Img\img.jpg", FileMode.Open)) { // Create a document using ms. using (DocX document = DocX.Load(str)) { DMF Dmf = new DMF(workflowProperties.Item); //RegexOptions options = new RegexOptions(); //Formatting newFormatting = new Formatting(); //MatchFormattingOptions fo = MatchFormattingOptions.SubsetMatch; FileIOPermission f = new FileIOPermission(PermissionState.None); f.AllLocalFiles = FileIOPermissionAccess.Read; //document.ReplaceText("RF_Title", Dmf.title); //document.ReplaceText("Product_Name", Dmf.productBrandName, false, options, newFormatting, newFormatting, fo); //document.ReplaceText("RMD_Zone_Overall", Dmf.overallDescription[0].ToString(), false, options, newFormatting, newFormatting, fo); //// Do something with the document here. //// Insert a Paragraph into this document. Paragraph p1 = document.InsertParagraph(Dmf.title); //// Append some text and add formatting. // p1.Append(Dmf.title) //.StyleName="Heading1"; // Add a new Paragraph to this document. Paragraph p = document.InsertParagraph("Here is Picture 1", false); // Add an Image to this document Novacode.Image img = document.AddImage(fs); f.Demand(); // Insert pic at the start of Paragraph p. Picture pic = img.CreatePicture(); p.InsertPicture(pic, 0); //foreach (string element in Dmf.typeOfSubmition) //{ // Paragraph p1 = document.InsertParagraph(); // // Append some text and add formatting. // p1.Append(element.ToString()) // .Font(new FontFamily("Times New Roman")) // .FontSize(14) // .Color(Color.Black) // .Bold(); //} // Save all changes made to this document. document.Save(); }// Release this document from memory // Add the document to the SharePoint site SPDocumentLibrary RFLib = Web.Lists["RF"] as SPDocumentLibrary; RFLib.RootFolder.Files.Add(workflowProperties.Item.Title + ".docx", str.ToArray(), true); } } } }
Code de l'erreure :Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
- Modifié Luthien0 mardi 4 décembre 2012 10:40
- Déplacé Gokan OzcifciMVP mardi 4 décembre 2012 11:46 (Origine :Sharepoint 2013,2010, 2007 et versions antérieures pour les professionnels IT)
Réponses
-
Bonjour,
Il devrait y avoir quelques éléments de réponses ici : http://social.msdn.microsoft.com/forums/en-US/asmxandxml/thread/b1db5b9f-50a4-4a21-aba1-afeb30957efd
En espérant que cela vous aide ;)
Pascal P
http://sharepoint-afterwork.fr
Twitter: @PascalPoeck
Facebook : https://www.facebook.com/SharePointAfterWork- Proposé comme réponse Gokan OzcifciMVP jeudi 6 décembre 2012 12:27
- Marqué comme réponse Gokan OzcifciMVP dimanche 9 décembre 2012 13:05
Toutes les réponses
-
Bonjour,
Il devrait y avoir quelques éléments de réponses ici : http://social.msdn.microsoft.com/forums/en-US/asmxandxml/thread/b1db5b9f-50a4-4a21-aba1-afeb30957efd
En espérant que cela vous aide ;)
Pascal P
http://sharepoint-afterwork.fr
Twitter: @PascalPoeck
Facebook : https://www.facebook.com/SharePointAfterWork- Proposé comme réponse Gokan OzcifciMVP jeudi 6 décembre 2012 12:27
- Marqué comme réponse Gokan OzcifciMVP dimanche 9 décembre 2012 13:05
-
Merci,
ça marche bien.
Pour info il fallait changer une ligne du web.config
<trust
level="Full"
originUrl=""
/>en mettant le level a Full
En revanche je me demande si il n'y a pas une autre facon de proceder.
Je m'explique, l'application est destiné à un client assez poitizeux niveau securtié et je ne suis pas sur qu'il accepte cette solution.
Quel peuvent etre les risques ?
-
Bonjour,
En plus de la réponse de Pascal, je ne sais pas si l'accès au bureau de l'utilisateur est juste un test ou si on suppose que l'on aura réellement accès aux fichiers de l'utilisateur.
C'est vrai lorsqu'on développe avec un serveur et un client qui sont la même machine mais cela deviendra faux en conditions réelles avec un serveur et un client qui seront des machines séparées...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".