Hi, I have a class that implements a thread which check whether a certain file exist or not (pdf file). If the file exist the thread should open the file on the browser then kill itself (the thread) but Im having a problem with Response.WriteFile() method, I always encountering an error saying "object not set to an instance." I'll Attach my code here.Please Help ASAP. Thanks FIRST CLASS . . . . FileTracker f = new FileTracker("c:\\Temp\\BCS_Temp.pdf"); f.createFinder(); . . . . SECOND CLASS using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;
//--using System.Threading; using System.IO;
namespace ThreadTest {
/// <summary> /// Summary description for Finder. /// </summary> /// public class FileTracker { public static string m_strRptFile; static Thread thread; public FileTracker(string FileName) { // // TODO: Add constructor logic here // m_strRptFile = FileName; }
public void ThreadStart() { FindFileExist(); }
public void createFinder() { FileTracker f = new FileTracker(m_strRptFile); thread = new Thread(new ThreadStart(f.ThreadStart)); thread.Priority = System.Threading.ThreadPriority.Lowest; thread.Start(); }
public void FindFileExist() { for(;;) { if(File.Exists(m_strRptFile)) { //WebForm1.strF = m_strRptFile; HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.WriteFile(strF); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.Close(); thread.Abort(); } }
}}}