Access to the path is denied.

Hello Guys,

Currently, we are facing with an interesting problem.
We are trying to convert an HTML to PDF with HtmlToPdfConverter class.

Sometimes on one developer machine we're getting an Exception, when we call the Convert method:
"Access to the path is denied  „C:\\Users\\emilh\\AppData\\Local\\Temp\\9188d02b-20de-4c41-b3fe-820e619bcbf9”
emilh is the user folder, and the file name always a uuid without file extension.
If the file is deleted, then conversion runs without any error. Another interesting point: we don't get it on every machine.

Have you ever met with this problem or do you have any guess to solve the problem?

Thank you in advance!



7 Replies

PV Prakash Viswanathan Syncfusion Team October 17, 2017 11:08 AM UTC

Hi Zsolt, 

Thanks for contacting Syncfusion support. 

While converting HTML to PDF using our WebKit HTML converter, we internally creating temporary files in temp folder. So, it requires read/write/run permissions for the temporary folder. By default, WebKit HTML converter gets system temp folder for creating temporary files for conversion. The access to the path is denied exception may occurs, if the temp path does not have the elevated permission. So, please check the temporary folder has elevated permission.  

We can change the temp path by using the TempPath property of WebKitConverterSettings. We can set the folder path, which has read/write/run permissions for the application. If we set the TempPath then the converter makes use of this path for creating temporary files. Please set the folder path to TempPath, which folder has elevated permission.  Refer below code snippet to set temp folder.    
WebKitConverterSettings webKitSettings = new WebKitConverterSettings(); 
webKitSettings.TempPath = "D://Project/Temp"; 

Regards, 
Prakash V 



ZJ Zsolt Jandzso October 17, 2017 02:40 PM UTC

Hello Prakash,

the temp folder has elevated permissions, so it cannot be a problem.

It is interesting, this problem only occurs occassionaly (not in case of all conversion) and not in all the devices.



CM Chinnu Muniyappan Syncfusion Team October 18, 2017 07:16 AM UTC

Hi Zsolt, 
 
Thank you for your update. 
 
We have tried to reproduce the reported issue from our side, but the issue is not reproduced in our side so that we would like to set up a web meeting to look into the issue and provide an appropriate solution. A support incident has been created under your account. Please log on to our support website to check for further updates 
 
Regards, 
Chinnu 



AH Ali Hatam replied to Zsolt Jandzso December 13, 2017 05:21 PM UTC

Hello Prakash,

the temp folder has elevated permissions, so it cannot be a problem.

It is interesting, this problem only occurs occassionaly (not in case of all conversion) and not in all the devices.


I have exactly same problem
I changed the temp folder with snippet code and let permission for Everyone with full control but get the same error : 

Access to the path 'C:\inetpub\wwwroot\SourceCode\PublishWeb\Content\webkit\6ebd0dd8-4216-42fa-a533-a1ee473f3ee1


Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\SourceCode\PublishWeb\Content\webkit\6ebd0dd8-4216-42fa-a533-a1ee473f3ee1' is denied. 

the folder : "C:\inetpub\wwwroot\SourceCode\PublishWeb\Content\webkit" has full control permission for everyone


PV Prakash Viswanathan Syncfusion Team December 14, 2017 12:56 PM UTC

Hi Ali Hatam, 

Thanks for using Syncfusion products. 

The access denied exception may occurs due to the temp path does not have required permission for respective user. Can you please try different temporary path and let us know the result. If you are hosting your application in IIS, please try to add IIS_IUSRS user group and provide full access permission to the temp folder.  

Also, please provide below details, so that we can analyze further.  
  1. Does the error occur for all input URLs or any particular URL?
  2. Is this occurring in all the machine or in server?

Regards, 
Prakash V 



AA Abdul Akher January 14, 2021 05:08 AM UTC

Hi,
I am using below simple codes to generate pdf with url as well as html string.
both generating pdf well in development machine but when deploying to server, error coming as "access denied"

HtmlToPdfConverter converter = new HtmlToPdfConverter();
WebKitConverterSettings settings = new WebKitConverterSettings();
settings.TempPath = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\temp"}";
settings.WebKitPath = Path.Combine(_honstingEnvironment.ContentRootPath, "QtBinariesDotNetCore");
converter.ConverterSettings = settings;

//string htmlText = "<html><body><img src=\"Bloom_Logo_Icon.png\" alt=\"Bloom_logo\" width=\"200\" height=\"70\"><p> <h1>Hello World</h1></p>"+strHtml + "</body></html>";          
//string baseUrl = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images"}";
//PdfDocument document = converter.Convert(htmlText, baseUrl);

PdfDocument document = converter.Convert(http://bloom/emp/Empcourse);

MemoryStream ms = new MemoryStream();
document.Save(ms);
document.Close(true);           
ms.Position = 0;
fileStreamResult = new FileStreamResult(ms, "application/pdf");
fileStreamResult.FileDownloadName = "Sample.pdf";
return fileStreamResult;

***I am using QtBinariesDotNetCore folder under my project directory.
all files copying to server while deploying.

any advice please?




GK Gowthamraj Kumar Syncfusion Team January 15, 2021 11:38 AM UTC

Hi Abdul,  
  
Thank you for contacting Syncfusion support.  
  
The access denied exception may occurs due to the permission restriction on temporary folder. WebKit HTML converter internally creates and launches a surrogate process from a temporary folder. So, the converter required read/write and execute permission of the temporary folder. If the temporary folder does not have the elevated permission, the reported exception may occurs. So, kindly ensure the respective user group has the permission for the temp folder.   
 
However, we can provide a particular path as temp path which has the elevated permission using TempPath property in WebKitConverterSettings then the converter will make use of system temporary folder for creating temporary files.   
 
If the application is hosted on IIS, then make sure the temp folder has read/write/execute permission of IIS_IUSRS user group. Also, kindly try the conversion with Local System identity and let us know the result.   
 
Kindly make sure that you are using Syncfusion assemblies and QtBinaries from same version of HTML converter installer or NuGet package.   
 
Kindly check the Syncfusion.HtmlConverter.Base.dll is blocked or not, if it is blocked please try the conversion after unblock it.   
 
Please refer below link for more information.   
 
Kindly try the above suggestions and if still the same exception occurs, kindly let us know the details about your server environment such as OS, Bit version, culture settings, RAM etc., so that we can try the conversion in same environment.   
  
Regards,  
Gowthamraj K   


Loader.
Up arrow icon