C# check if text file is empty


















You're assuming Temp contains 4 elements, which is probably where your errors are coming from with a blank file. I'd highly suggest something along the lines of the following I agree, definitely check the file size with FileInfo.

Length and define what you should do if the file is empty, etcetera. Post Reply. How do I check if a file is empty in C?? StreamReader read last line in a text file. How to create a new empty text file? Question about difference between text file and database. Reading data from serial port and saving it in text file. Checking if a text file is blank.

Error in Downloading the text file. Mobile Development. Adding a new footer. Opening Balance. Undesired Name? Follow us! Get the Latest Bytes Updates. By using this site, you agree to our Privacy Policy and Terms of Use. Check for empty text file klharding 13 I am reading the contents of a text file into variables.

Oct 9 '09 reply tlhintoq 3, Expert 2GB add the using statements using System. Oct 14 '09 reply klharding 13 Ok, the following seems to work, although I am still getting errors on a blank text file. Now, mdc ;. For storing file into database first you have to convert into Byte Array Format, then you can store into DataBase. Use this sample code for that-. Open, FileAccess. Read imageSize, 0, int FileUpload1. ContentLength ;. I would like to set a default logo if the user did not choose an image I have the following code:.

ConnectionStrings[ "db 2 ConnectionString" ]. ConnectionString ;. Open ;. ExecuteReader ;. Read ;. ToString ;. GetExtension FileUpload1. FileName ;. SaveAs Server. MapPath ". Close ;. Untitled document. Exists pathToCheck. SaveAs savePath ;. Sign in Email. Forgot your password? Ask a Question. Reading an empty text file problem. Please Sign up or sign in to vote. See more: C. Hi friends, As part of a software I am working on, an empty text file "filex. I write the activation status which is just a string to this file on registration of the software and at every start-up, I read the content of this file to verify registration.

The problem is that I get an error when I run that bit of the software so I isolated that bit into a test project and still get an error. The Exception message that I caught says: "Object Reference not set to an instance of an object". The bit of code I tried in the test project is shown below: C.

Copy Code. Posted 1-Aug am smilerP. Add a Solution. Top Rated Most Recent. Accept Solution Reject Solution. Try this: C. Manas Bhardwaj 1-Aug pm. The actual cause still remains the same. Bad file path???? Try: C. Posted 1-Aug am OriginalGriff.



0コメント

  • 1000 / 1000