Excel to Pdf in C# using Pdftron - c#

I am trying to convert an Excel document into PDF in a ASP.Net Web application using Pdftron (Pdfnet) library.
Following is my code for the above purpose.
pdf.PDF.PDFDoc newSalaryFitmentPdf = new pdf.PDF.PDFDoc();
pdftron.PDF.Convert.ToPdf(newSalaryFitmentPdf, newSalaryFitmentExcel.FullName);
salaryFitment = newSalaryFitmentPdf.Save(pdf.SDF.SDFDoc.SaveOptions.e_linearized);
But I am getting the following exception when the program is trying to execute the second line.
Exception:
Message: An error occurred while converting the file.
Detailed error:
Error creating a new Excel application instance.
Code: PDFTRON_UNKNOWN (-2147024891)
File: "Excel.cpp":51
Log:
Start check system account.
Session ID is: 0.
Failed to create Desktop folder in SystemProfile. boost::filesystem::create_directory: Access is denied: "C:\Windows\system32\config\systemprofile\Desktop"
Failed to create Desktop folder in SystemProfile. boost::filesystem::create_directory: Access is denied: "C:\Windows\SysWOW64\config\systemprofile\Desktop"
Done checking system account.
Creating an Excel application instance.
Conditional expression: false
Version : 6.7.1.61823N
Filename : Convert.cpp
Function : trn::PDF::Convert::ToPdf
Linenumber : 1692
Any help would be highly appreciated.

Failed to create Desktop folder in SystemProfile. boost::filesystem::create_directory: Access is denied: "C:\Windows\system32\config\systemprofile\Desktop"
Failed to create Desktop folder in SystemProfile. boost::filesystem::create_directory: Access is denied: "C:\Windows\SysWOW64\config\systemprofile\Desktop"
You must set your application to have read/write access to these directories. Please see this article for further information.

Related

Search a file in a library Graph API

Running the query :
https://graph.microsoft.com/v1.0/me/drive/root/search(q='File.txt')
It works in graph explorer, but when I try to run the same in console application with proper AuthProvider and Permissions, it is giving access denied error.
Used documentation : https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http
Gave all the App permissions ...
Is there any other way to check if a file is present in a library or not ?

Access Denied when creating SQLite DB file

I'm trying to create the database file to initialize it but I'm getting "Access Denied" error during execution. I think is something related with permissions but I'm not able to find any information that could fix it, since every guide I check does it the same way.
This is an UWP application using C# and SQLite library. Thanks in advance for the help.
In the past I've tried to also create json file with other methods but I've never been able to create a file from a UWP application
Code that raises an error:
private const string DBName = "data.sqlite";
if (!File.Exists(Path.GetFullPath(DBName)))
{
SQLiteConnection.CreateFile(DBName);
RecentlyCreated = true;
}
Error message:
System.UnauthorizedAccessException: 'Access to the path 'C:\Users\myuser\source\repos\Pass\Pass\bin\x64\Debug\AppX\dataAccount.sqlite'
is denied.'
UWP has a very limited access to the user filesystem, as it described at File access permissions specification. You can use user libraries (downloads, documents) for storing the data (after allowing an access in appxmanifest file) or application data store (more viable in your case). Try to define DBName as
string DBName = ApplicationData.Current.LocalFolder.Path + #"\data.sqlite";
Or you can allow broadFileSystemAccess using link above

Set path to GeoIpDB in asp.net application

I'm having trouble setting path to GeoIp database in my asp.net application.
I have db file in my application root folder, but when i call
using (var reader = new DatabaseReader("GeoLite2-City.mmdb"))
exception "file not found" is thrown.
When i pass full local path #"d:\documents\vsprojects\app\GeoLite2-City.mmdb" to DatabaseReader, application is working. Is there a way to fix this, because this would not work when i upload app to host?
Edit: When i try to access file directly, with http://localhost:45500/GeoLite2-City.mmdb i get an 404.3 error.

Premissions to access LDAP from a windows service

I'm building a windows service that polls a windows file share location for a file containing members that may be found in LDAP. The windows service is running as a specific user on the domain to have access to the file share. This user is in the Administrator group both on the server running the service and where LDAP is found.
The problem I have is that fetching the files works fine but then when accessing LDAP I get the following exception:
LDAPService.Program - Exception: An operations error occurred.
InnerEx:
=== STACKTRACE ===
LDAPService.Program - at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind() at
System.DirectoryServices.DirectoryEntry.RefreshCache()
=== BASE EXC ===
LDAPService.Program - System.DirectoryServices.DirectoryServicesCOMException (0x80072020): An operations error occurred.
Searching for this error there is a lot about ASP.NET and using Impersonate(). But that didn't help.
If I change the windows service to logon as Local System Account then I have no problems accessing LDAP (but I can't access the windows file share).
What other settings should I look at?
I was using two different LDAP directories and forgot to provide the user/pass for the second one. Had only given it for the first one.
A classic example of what we call SBS here in Sweden (Skit Bakom Spakarna).

Open File on Network As A Different User

I have a .NET windows application I am writing in which I want to run "explorer.exe" to open a file. Basically, I have this program that shows users files (in a grid) that is in a folder on the network in which they do not have access to. So basically I want them to be able to view certain files (like Doc(x), PDF, JPG, etc). When they click on the file in the grid, I want it to launch the appropriate application for the extension of the selected file. When using this as myself it was working using:
Process.Start("explorer.exe", #"\\myserver\folder\test.pdf");
However, these files are in a location that the actual users do not have access to. I tried wrapping it with the following:
using (new Impersonator("username", "domain", "password"))
{
}
But I got error:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
Additional information: Unknown error (0xfffffffe)
I even tried using ProcessStartInfo and setting username, password and domain there but kept getting:
The directory name is invalid.
So any ideas on how to launch a file (i.e. Doc(x), PDF, JPG, etc.) with giving it credentials of a user that has access to that folder on the network?

Categories