0

I am using DocumentFormat dll in my application to write a Word file from another Word file. The file from which I copy the contents is placed on 14 hive location. When I try accessing it using the code given below:

WordprocessingDocument objWordDocx = WordprocessingDocument.Open(sTempFileName, true);

An exception

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

is thrown. I am unable to figure out the issue. Please guide.

1

That may be because your DLL hosting the code is deployed into the \bin folder and not into the GAC. GACed DLL have Full control, while \bin DLL have a limited set of permissions (that can be changed in a .config files).

You can ensure your main DLL is deployed to GAC in Visual Studio: select the project in Visual Studio, and change the "Assembly Deployment Target" from GlobalAssemblyCache to WebApplication in the properties window. See first screenshot at http://captechconsulting.com/blogs/sharepoint-without-the-gac.

You also have to check deployment targets for other secondary DLLs you may have added in the "Advanced" tab of the Package page.

In all cases, accessing files in the \14 hive is probably not a best practice here. Why don't you put the source file in a document Library (and access it via the SharePoint object-model)? That would even bring the benefice of updating that file later without redeploying anything in the \14 hive.

  • Not an easy task... First of all, don't you want to put the DLL into the GAC instead of \bin, to check we're on track? By th way, how did you deploy your solution? – Evariste Jul 28 '15 at 6:38
  • You can change this setting in Visual Studio: select the project in Visual Studio, and change the "Assembly Deployment Target" from GlobalAssemblyCache to WebApplication in the properties window. See first screenshot at captechconsulting.com/blogs/sharepoint-without-the-gac. – Evariste Jul 28 '15 at 6:56
  • Sorry, I meant from WebApplication to GlobalAssemblyCache in y previous comment. What was the situation before you changed? You need GlobalAssemblyCache. – Evariste Jul 28 '15 at 7:14
  • 1
    I'm pretty sure it's a CAS policy problem and not a file access problem. Can you check whether the DLL can be found in the folder C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin? If yes, please, remove it. Ensure it is in visible in C:\Windows\assembly. IISRESET. Test. Also, where is deployed DocumentFormat.OpenXml.dll? How did you add it to the WSP package? Check its deployment target from the package Advanced tab, and manually double-check with the same steps as for your own DLL. – Evariste Jul 28 '15 at 7:26
0

Go to the Package and navigate to the the Advanced tab. Add the DLL here. Also as said ny @Evariste in his comment above, remove the DLL from

C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin

location. This will help you to get rid of the exception mentioned above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.