Click here to Skip to main content
15,393,837 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to convert PDF File to Base 64 and send this to some web service. My PDF is Located inside my application folder and stored its path to database.
When i used this path from db and its shows error.

What I have tried:

I tried to get file name only from last index and merge with virtual path with Server.MapPath("~/upload/xyz.pdf") and try to read and convert it to Base64, but still i m not solving the error.
Updated 28-May-21 3:21am
Richard MacCutchan 28-May-21 9:03am
"its shows error."
What makes you believe that a bunch of strangers on the internet can see the error message on your screen?

We have no idea what your error might be - you don't tell us - and we have no access at all to your server file system.
Add to that that we can't see your code, or test your application in any way, and there is nothing we can do at all to help you!

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do any of that for you - time for you to learn a new (and very, very useful) skill: debugging!
You said, "
When i used this path from db and its shows error.

I'm going to focus on that part.
It would've been really helpful to display the exact error, but I'm assuming that you ASP.NET app cannot access the path.

This fix can very likely be made in file system.

You need to go to the folder where the PDF files are located -- if it is multiple folders try one first and figure out how to change all of them later -- and right click on the folder and select properties.[^]

Next, is the difficult part. You have to know what user your ASP.NET app is running under.

It's probably under the DefaultAppPool in inetmgr (IIS).[^]

Once you know which user your ASP.NET application is running under then that is the user you need to give access to the folder.

Give that user full (read/write) rights while you test. You can figure out the rest and tighten down security later.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900