A progam that read a fild and checks if it's true
An HTML file starts with and ends with . Write a program that reads a file and checks whether that is true.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Dec 8, 2009, 9:45 PM
Here is Code for that
if my answer helps you then check "Do you like this answer" check box please :)
private void button1_Click(object sender, EventArgs e)
{
string Data = File.ReadAllText("test.html");
if (Data.StartsWith(".") == true && Data.EndsWith(".") == true)
{
MessageBox.Show("Validation Success!!");
}
else
{
MessageBox.Show("Validation Failed!!");
}
}
Lalit MPosted Dec 9, 2009, 12:21 AM
///
/// method to check not only if a file is already open, but if the
/// but also if read and write permissions exist
///
/// the file we wish to check
///
public bool isFileOpenOrReadOnly(ref string file)
{
try
{
//first make sure it's not a read only file
if ((File.GetAttributes(file) & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)
{
//first we open the file with a FileStream
using (FileStream stream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
{
try
{
stream.ReadByte();
return false;
}
catch (IOException)
{
return true;
}
finally
{
stream.Close();
stream.Dispose();
}
}
}
else
return true;
}
catch (IOException)
{
return true;
}
}
more reference link --->Thanks.
Hiren SoniPosted Dec 8, 2009, 9:57 PM
Sam HobbsPosted Dec 8, 2009, 6:01 PM