asp.net worker process locking files

R

rao

Hi All,

I am generating temporary xml files to bind it to tree view control.
A unique xml file is generated for each user. I generating these files
Using streamwriter class. Later when I try to delete the file with
File.Dlete in page unload event I gets an error File already in use by
another process. When I examine process explorer aspnet_wp.exe is hold
these files.
Here is the code I am working on.. Any advise please.


Thanks in advance
Rao







private void Page_UnLoad(object sender, System.EventArgs e)
{
try
{
if (File.Exists(Server.MapPath(xmlDocPath+ProjectsDoc)))
{ ProjectTree.Dispose();
File.Delete(Server.MapPath(xmlDocPath+ProjectsDoc));
}

}
catch(Exception ex)
{SetErrorMessage(ex.Message.ToString(),true);
}
}


private void InitializeTreeView()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.TreeNodeSrc=
DataRetrieval.formatXMLforTree("eacollin.ProjectXML");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("eacollin.ProjectXML");
ProjectTree.TreeNodeSrc= Server.MapPath(xmlDocPath+ProjectsDoc);
ProjectTree.DefaultStyle.CssText="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.DataBind();
ProjectTree.Dispose();
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Unload+=new System.EventHandler(this.Page_UnLoad);
//ProjectTree.Unload+=new System.EventHandler(this.DeleteXmlFiles);

}



public static string PrepareProjectsXMLdoc(string SPname)
{
// added by rao 8/27/2004
// added projects cache to avoid round trip to sql server, and
// additional processing involved in process returned xml from
// stored procedure
string strXML;
strXML="";
DataSet ds=new DataSet();
string OutFileName="";
System.IO.StringWriter strWriter = new StringWriter();
try
{


if(System.Web.HttpContext.Current.Cache["Projects"]==null)
{

ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[ASPNET.StarterKit.TimeTracker.Web.Global.CfgKeyConnString],
SPname);

strXML = "";
ds.WriteXml(strWriter);
strXML = strWriter.ToString();

//get rid of the text version of < and > tags
strXML = Regex.Replace(strXML, "&lt;", "<");
strXML = Regex.Replace(strXML, "&gt;", ">");

//get ride of the XML headers
string search =
@"</XML_F52E2B61-18A1-11d1-B105-00805F49916B>\s*</Table>\s*<Table>\s*<XML_F52E2B61-18A1-11d1-B105-00805F49916B>";
strXML = Regex.Replace(strXML,search,"");

//Get rid of apostrophes which do not show up properly on the
webpage
strXML = Regex.Replace(strXML,"&amp;apos;","'");

//find the part of the xml that starts and ends with TREENODES
int firstoccurance = strXML.IndexOf("TREENODES");
int secondoccurance =
strXML.IndexOf("TREENODES",firstoccurance+1);
int delta = secondoccurance - firstoccurance;
strXML = strXML.Substring(firstoccurance,delta);
strXML = "<" + strXML + "TREENODES>";
ds.Dispose();

// generate uniqe filename for each user
lock(System.Web.HttpContext.Current.Cache)
{

System.Web.HttpContext.Current.Cache.Insert("Projects",strXML,null,
DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingExpiration);
}

}
else
{
strXML =(string)System.Web.HttpContext.Current.Cache["Projects"];

}
string NewGuid = System.Guid.NewGuid().ToString();
OutFileName=NewGuid+"_Projects.xml";

using(StreamWriter wr = new
StreamWriter(System.Web.HttpContext.Current.Server.MapPath(xmlDocPath+OutFileName)))
{
wr.Write(strXML);
}


strWriter.Close();

//return OutFileName;
}
catch(Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.Message);
}
return OutFileName;
}
 
M

Marina

Is it possible for the treeview control to take something else other then a
file path? You really would want to avoid writing and deleting files for
each user

rao said:
Hi All,

I am generating temporary xml files to bind it to tree view control.
A unique xml file is generated for each user. I generating these files
Using streamwriter class. Later when I try to delete the file with
File.Dlete in page unload event I gets an error File already in use by
another process. When I examine process explorer aspnet_wp.exe is hold
these files.
Here is the code I am working on.. Any advise please.


Thanks in advance
Rao







private void Page_UnLoad(object sender, System.EventArgs e)
{
try
{
if (File.Exists(Server.MapPath(xmlDocPath+ProjectsDoc)))
{ ProjectTree.Dispose();
File.Delete(Server.MapPath(xmlDocPath+ProjectsDoc));
}

}
catch(Exception ex)
{SetErrorMessage(ex.Message.ToString(),true);
}
}


private void InitializeTreeView()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.TreeNodeSrc=
DataRetrieval.formatXMLforTree("eacollin.ProjectXML");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("eacollin.ProjectXML");
ProjectTree.TreeNodeSrc= Server.MapPath(xmlDocPath+ProjectsDoc);
ProjectTree.DefaultStyle.CssText="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.DataBind();
ProjectTree.Dispose();
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Unload+=new System.EventHandler(this.Page_UnLoad);
//ProjectTree.Unload+=new System.EventHandler(this.DeleteXmlFiles);

}



public static string PrepareProjectsXMLdoc(string SPname)
{
// added by rao 8/27/2004
// added projects cache to avoid round trip to sql server, and
// additional processing involved in process returned xml from
// stored procedure
string strXML;
strXML="";
DataSet ds=new DataSet();
string OutFileName="";
System.IO.StringWriter strWriter = new StringWriter();
try
{


if(System.Web.HttpContext.Current.Cache["Projects"]==null)
{

ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[ASPNET.StarterKit
..TimeTracker.Web.Global.CfgKeyConnString],
SPname);

strXML = "";
ds.WriteXml(strWriter);
strXML = strWriter.ToString();

//get rid of the text version of < and > tags
strXML = Regex.Replace(strXML, "&lt;", "<");
strXML = Regex.Replace(strXML, "&gt;", ">");

//get ride of the XML headers
string search =
@ said:
strXML = Regex.Replace(strXML,search,"");

//Get rid of apostrophes which do not show up properly on the
webpage
strXML = Regex.Replace(strXML,"&amp;apos;","'");

//find the part of the xml that starts and ends with TREENODES
int firstoccurance = strXML.IndexOf("TREENODES");
int secondoccurance =
strXML.IndexOf("TREENODES",firstoccurance+1);
int delta = secondoccurance - firstoccurance;
strXML = strXML.Substring(firstoccurance,delta);
strXML = "<" + strXML + "TREENODES>";
ds.Dispose();

// generate uniqe filename for each user
lock(System.Web.HttpContext.Current.Cache)
{

System.Web.HttpContext.Current.Cache.Insert("Projects",strXML,null,
DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingExpiration);
}

}
else
{
strXML =(string)System.Web.HttpContext.Current.Cache["Projects"];

}
string NewGuid = System.Guid.NewGuid().ToString();
OutFileName=NewGuid+"_Projects.xml";

using(StreamWriter wr = new
StreamWriter(System.Web.HttpContext.Current.Server.MapPath(xmlDocPath+OutFil
eName)))
{
wr.Write(strXML);
}


strWriter.Close();

//return OutFileName;
}
catch(Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.Message);
}
return OutFileName;
}
 
R

rao

Hi Marina,

I am doing this for performance reason. Binding to xml stream or
dataset
causing lot of time to render page as my data is huge when I am using
tree view control. Any other solutions are welcome.


Thanks
Rao


Marina said:
Is it possible for the treeview control to take something else other then a
file path? You really would want to avoid writing and deleting files for
each user

rao said:
Hi All,

I am generating temporary xml files to bind it to tree view control.
A unique xml file is generated for each user. I generating these files
Using streamwriter class. Later when I try to delete the file with
File.Dlete in page unload event I gets an error File already in use by
another process. When I examine process explorer aspnet_wp.exe is hold
these files.
Here is the code I am working on.. Any advise please.


Thanks in advance
Rao







private void Page_UnLoad(object sender, System.EventArgs e)
{
try
{
if (File.Exists(Server.MapPath(xmlDocPath+ProjectsDoc)))
{ ProjectTree.Dispose();
File.Delete(Server.MapPath(xmlDocPath+ProjectsDoc));
}
}
catch(Exception ex)
{SetErrorMessage(ex.Message.ToString(),true);
}
}


private void InitializeTreeView()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.TreeNodeSrc=
DataRetrieval.formatXMLforTree("eacollin.ProjectXML");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("eacollin.ProjectXML");
ProjectTree.TreeNodeSrc= Server.MapPath(xmlDocPath+ProjectsDoc);
ProjectTree.DefaultStyle.CssText="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.DataBind();
ProjectTree.Dispose();
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Unload+=new System.EventHandler(this.Page_UnLoad);
//ProjectTree.Unload+=new System.EventHandler(this.DeleteXmlFiles);

}



public static string PrepareProjectsXMLdoc(string SPname)
{
// added by rao 8/27/2004
// added projects cache to avoid round trip to sql server, and
// additional processing involved in process returned xml from
// stored procedure
string strXML;
strXML="";
DataSet ds=new DataSet();
string OutFileName="";
System.IO.StringWriter strWriter = new StringWriter();
try
{


if(System.Web.HttpContext.Current.Cache["Projects"]==null)
{

ds = SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[ASPNET.StarterKit
.TimeTracker.Web.Global.CfgKeyConnString],
SPname);

strXML = "";
ds.WriteXml(strWriter);
strXML = strWriter.ToString();

//get rid of the text version of < and > tags
strXML = Regex.Replace(strXML, "&lt;", "<");
strXML = Regex.Replace(strXML, "&gt;", ">");

//get ride of the XML headers
string search =
@ said:
strXML = Regex.Replace(strXML,search,"");

//Get rid of apostrophes which do not show up properly on the
webpage
strXML = Regex.Replace(strXML,"&amp;apos;","'");

//find the part of the xml that starts and ends with TREENODES
int firstoccurance = strXML.IndexOf("TREENODES");
int secondoccurance =
strXML.IndexOf("TREENODES",firstoccurance+1);
int delta = secondoccurance - firstoccurance;
strXML = strXML.Substring(firstoccurance,delta);
strXML = "<" + strXML + "TREENODES>";
ds.Dispose();

// generate uniqe filename for each user
lock(System.Web.HttpContext.Current.Cache)
{

System.Web.HttpContext.Current.Cache.Insert("Projects",strXML,null,
DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingExpiration);
}
}
else
{
strXML =(string)System.Web.HttpContext.Current.Cache["Projects"];

}
string NewGuid = System.Guid.NewGuid().ToString();
OutFileName=NewGuid+"_Projects.xml";

using(StreamWriter wr = new
StreamWriter(System.Web.HttpContext.Current.Server.MapPath(xmlDocPath+OutFil
eName)))
{
wr.Write(strXML);
}


strWriter.Close();

//return OutFileName;
}
catch(Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.Message);
} return OutFileName;
}
 
D

drippy

Rao,

Did you ever find a way around this? I am having the same problem and
have noticed that the file gets locked when I close my browser with the
treeview open. Thanks,

drippy
Hi Marina,

I am doing this for performance reason. Binding to xml stream or
dataset
causing lot of time to render page as my data is huge when I am using
tree view control. Any other solutions are welcome.


Thanks
Rao


"Marina" <[email protected]> wrote in message
Is it possible for the treeview control to take something else other then a
file path? You really would want to avoid writing and deleting files for
each user

rao said:
Hi All,

I am generating temporary xml files to bind it to tree view control.
A unique xml file is generated for each user. I generating these files
Using streamwriter class. Later when I try to delete the file with
File.Dlete in page unload event I gets an error File already in use by
another process. When I examine process explorer aspnet_wp.exe is hold
these files.
Here is the code I am working on.. Any advise please.


Thanks in advance
Rao







private void Page_UnLoad(object sender, System.EventArgs e)
{
try
{
if (File.Exists(Server.MapPath(xmlDocPath+ProjectsDoc)))
{ ProjectTree.Dispose();
File.Delete(Server.MapPath(xmlDocPath+ProjectsDoc));
}
}
catch(Exception ex)
{SetErrorMessage(ex.Message.ToString(),true);
}
}


private void InitializeTreeView()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.TreeNodeSrc=
DataRetrieval.formatXMLforTree("eacollin.ProjectXML");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("eacollin.ProjectXML");
ProjectTree.TreeNodeSrc= Server.MapPath(xmlDocPath+ProjectsDoc);
ProjectTree.DefaultStyle.CssText="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.DataBind();
ProjectTree.Dispose();
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Unload+=new System.EventHandler(this.Page_UnLoad);
//ProjectTree.Unload+=new System.EventHandler(this.DeleteXmlFiles);

}



public static string PrepareProjectsXMLdoc(string SPname)
{
// added by rao 8/27/2004
// added projects cache to avoid round trip to sql server, and
// additional processing involved in process returned xml from
// stored procedure
string strXML;
strXML="";
DataSet ds=new DataSet();
string OutFileName="";
System.IO.StringWriter strWriter = new StringWriter();
try
{


if(System.Web.HttpContext.Current.Cache["Projects"]==null)
{

ds =
SqlHelper.ExecuteDataset(ConfigurationSettings.AppSettings[ASPNET.StarterKit
.TimeTracker.Web.Global.CfgKeyConnString],
SPname);

strXML = "";
ds.WriteXml(strWriter);
strXML = strWriter.ToString();

//get rid of the text version of < and > tags
strXML = Regex.Replace(strXML, "&lt;", "<");
strXML = Regex.Replace(strXML, "&gt;", ">");

//get ride of the XML headers
string search =
@ said:
2E2B61-18A1-11d1-B105-00805F49916B>";
strXML = Regex.Replace(strXML,search,"");

//Get rid of apostrophes which do not show up properly on the
webpage
strXML = Regex.Replace(strXML,"&amp;apos;","'");

//find the part of the xml that starts and ends with TREENODES
int firstoccurance = strXML.IndexOf("TREENODES");
int secondoccurance =
strXML.IndexOf("TREENODES",firstoccurance+1);
int delta = secondoccurance - firstoccurance;
strXML = strXML.Substring(firstoccurance,delta);
strXML = "<" + strXML + "TREENODES>";
ds.Dispose();

// generate uniqe filename for each user
lock(System.Web.HttpContext.Current.Cache)
{

System.Web.HttpContext.Current.Cache.Insert("Projects",strXML,null,
DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingExpiration);
}
}
else
{
strXML =(string)System.Web.HttpContext.Current.Cache["Projects"];

}
string NewGuid = System.Guid.NewGuid().ToString();
OutFileName=NewGuid+"_Projects.xml";

using(StreamWriter wr = new
StreamWriter(System.Web.HttpContext.Current.Server.MapPath(xmlDocPath+OutFil
eName)))
{
wr.Write(strXML);
}


strWriter.Close();

//return OutFileName;
}
catch(Exception ex)
{
System.Web.HttpContext.Current.Response.Write(ex.Message);
} return OutFileName;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top