Click here to Skip to main content
15,906,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am trying to open a text file and reading it line by line.But I am geting this exception please suggest me.
exception details:
System.UnauthorizedAccessException was caught
Message=Access to the path 'C:\Users\karthick.k\Desktop\OB8182301_20130823_020658.txt' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at StorageBase.SbWebPages.KortaPaymentImport.paymentKorta() in F:\GeymslurAlpha\StorageBase\SbWebPages\KortaPaymentImport.aspx.cs:line 214

Thank you all.

Try to change text file Location drive Except c:
Share this answer
Sivarjun Chikkala 13-Sep-13 1:49am    
Thank you very much KM Perumal.
It is working.
KM Perumal 13-Sep-13 3:40am    
It's complaining about the file because some part of the path is not accessible to the user that is running the application. Most likely this is because you are trying to access a file via a fixed address on the server of your website.

There are a couple of things here, but it's not obvious what you should do to fix it: if the file is on the server, then you should not be trying to access it via a user path, because there is absolutely no guarantee that your user even exists on a webserver, and there is almost no chance that a website will run under that user anyway.
There is also the chance that the file is on the client - in which case your code cannot access it at all unless it had been uploaded to the server first, in which case you should be saving if in a path relative to the website anyway.

I cannot make concrete suggestions here, because I can't see your code!
Share this answer

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