Note that there are some explanatory texts on larger screens.

plurals
  1. POReversing a tsv/csv file or reading only last line using asp.net
    primarykey
    data
    text
    <p>Hey guys i am pretty much stuck on a problem from last few days. I have a file while is located on a remote server can be access by using userId and password. Well no problem in accessing. </p> <p>Problem is i have around 150 of them. and each of them is of variable size minimum is 2 MB and max is 3 MB.</p> <p>I have to read them one by one and read last row/line data from them. I am doing it in my current code. </p> <p>The main problem is it is taking too much time since it is reading files from top to bottom.</p> <pre><code> public bool TEst(string ControlId, string FileName, long offset) { // The serverUri parameter should use the ftp:// scheme. // It identifies the server file that is to be downloaded // Example: ftp://contoso.com/someFile.txt. // The fileName parameter identifies the local file. //The serverUri parameter identifies the remote file. // The offset parameter specifies where in the server file to start reading data. Uri serverUri; String ftpserver = "ftp://xxx.xxx.xx.xxx/"+FileName; serverUri = new Uri(ftpserver); if (serverUri.Scheme != Uri.UriSchemeFtp) { return false; } // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); request.Credentials = new NetworkCredential("test", "test"); request.Method = WebRequestMethods.Ftp.DownloadFile; //request.Method = WebRequestMethods.Ftp.DownloadFile; request.ContentOffset = offset; FtpWebResponse response = null; try { response = (FtpWebResponse)request.GetResponse(); // long Size = response.ContentLength; } catch (WebException e) { Console.WriteLine(e.Status); Console.WriteLine(e.Message); return false; } // Get the data stream from the response. Stream newFile = response.GetResponseStream(); // Use a StreamReader to simplify reading the response data. StreamReader reader = new StreamReader(newFile); string newFileData = reader.ReadToEnd(); // Append the response data to the local file // using a StreamWriter. string[] parser = newFileData.Split('\t'); string strID = parser[parser.Length - 5]; string strName = parser[parser.Length - 3]; string strStatus = parser[parser.Length-1]; if (strStatus.Trim().ToLower() != "suspect") { HtmlTableCell control = (HtmlTableCell)this.FindControl(ControlId); control.InnerHtml = strName.Split('.')[0]; } else { HtmlTableCell control = (HtmlTableCell)this.FindControl(ControlId); control.InnerHtml = "S"; } // Display the status description. // Cleanup. reader.Close(); response.Close(); //Console.WriteLine("Download restart - status: {0}", response.StatusDescription); return true; } </code></pre> <p>Threading:</p> <pre><code> protected void Page_Load(object sender, EventArgs e) { new Task(()=&gt;this.TEst("controlid1", "file1.tsv", 261454)).Start(); new Task(()=&gt;this.TEst1("controlid2", "file2.tsv", 261454)).Start(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload