Question #38075

Hayley has started the application development. She needs to ensure that the application meets

the following requirements:

When the application starts, it should display a message asking the user to enter either option d or

v. The application should execute the following actions for the two options:

• d: The application should display the file extension of the stock details.

• v: The application should open the stock details file in the read-only mode and display its

contents.

Write the code snippet that Hayley should use to implement the desired functionality in the
application

Expert's answer

Answer on Question#38075- Programming, C#

1. Hayley has started the application development. She needs to ensure that the application meets the following requirements:

When the application starts, it should display a message asking the user to enter either option d or v. The application should execute the following actions for the two options:

- d: The application should display the file extension of the stock details.

- v: The application should open the stock details file in the read-only mode and display its contents.

Write the code snippet that Hayley should use to implement the desired functionality in the application

Solution.

Some times we may have to make file readonly programatically.

To make readonly...


foreach (string fileName in System.IO.Directory.GetFiles(path))
{
    System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
    fileInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
    // or
    fileInfo.IsReadOnly = true;
}


To change attribute readily only false


foreach (string fileName in System.IO.Directory.GetFiles(configFilePath))
{
    System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
    if(fileInfo.IsReadOnly == true)
        fileInfo.IsReadOnly = false;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS