CSV to TextReader

/// <summary>

/// Take a file path and return a TextReader

/// </summary>

/// <param name="file_path"></param>

/// <returns></returns>

private TextReader OpenFile (string file_path)

{

    try

    {

        // Read the CSV file in to a TextReader

        TextReader _rdr = File.OpenText(file_path);

        // Set file attributes

        File.SetAttributes(file_path, FileAttributes.Normal);

 

        return _rdr;

    }

    catch (Exception)

    {

        throw new Exception(String.Format(

                "Error trying to open file {0}. Check file exists and is accessible<br /><br />" +

                "Possible Issues:<br/><br />Files cannot be accessed via mapped network drives" +

                "<br />The file is open<br />The file has been viewed and then saved in Excel",file_path));

    }

}

No Comments