Click here to Skip to main content
14,423,178 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello friends,
I am using "CryptoStream" to read data from my encrypted file. If this file is empty it raises an exception. Now i want to check whether my file is empty or not.
Plz tell me the way.
Posted
Updated 22-May-10 1:32am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi friend.
you can use System.IO namespace to provide filing functionality. to check the availability of file you must go as under
<br />
if(File.Exist("File path"))<br />
{<br />
//perform encryption function here in<br />
}<br />
   
Comments
darora85 22-May-10 7:07am
   
thanks buddy.
J imran 22-May-10 9:04am
   
no problem...:)
William Winner 22-May-10 17:26pm
   
Reason for my vote of 2
while he marked it as an answer, it actually doesn't answer his question, which said if the file is empty. The language implies that the file exists, but has nothing in it. If that is the case in which the exception is being thrown, then this answer will not solve that problem.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Looking at the msdn sample here, I noticed that they check if while(rdlen < totlen) as a while condition.

You have not provided any code here, so I cannot be sure - but I guess a condition like this should be sufficient to avoid null errors? You can always directly check if an object is null by doing an if condidition check against it.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100