473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

asp.net worker process locking files

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.ProjectXM L");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("e acollin.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.App Settings[ASPNET.StarterKit.TimeTracker.Web.Global.CfgKeyCon nString],
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("Proje cts",strXML,null,
DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingEx piration);
}

}
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.M essage);
}
return OutFileName;
}
Nov 18 '05 #1
3 2910
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" <ja********@hotmail.com> wrote in message
news:f2************************@posting.google.com ...
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.ProjectXM L");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("e acollin.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.App Settings[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_F5
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("Proje cts",strXML,null,
DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingEx piration);
}

}
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.M essage);
}
return OutFileName;
}

Nov 18 '05 #2
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" <so*****@nospam.com> wrote in message news:<Ol**************@TK2MSFTNGP09.phx.gbl>...
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" <ja********@hotmail.com> wrote in message
news:f2************************@posting.google.com ...
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.ProjectXM L");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("e acollin.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.App Settings[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_F5
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("Proje cts",strXML,null,
DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingEx piration);
}

}
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.M essage);
}

return OutFileName;
}

Nov 18 '05 #3
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

rao wrote:
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" <so*****@nospam.com> wrote in message

news:<Ol**************@TK2MSFTNGP09.phx.gbl>...
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" <ja********@hotmail.com> wrote in message
news:f2************************@posting.google.com ...
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.ProjectXM L");

ProjectsDoc=DataRetrieval.PrepareProjectsXMLdoc("e acollin.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.App Settings[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_F5 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("Proje cts",strXML,null, DateTime.Now.AddHours(HoursLeft),Cache.NoSlidingEx piration);
}

}
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.M essage);
}

return OutFileName;
}


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Top Hat | last post by:
Greetings! My application uses several files that contain constants, error code, etc that are located in a directory call /bin. At times when I am testing the application in "debug" mode, the...
3
by: Trevor Andrew | last post by:
Hi There, I have a small ASP.NET application under development. I am using VS.NET 2002 (2003 upgrade is on the way) with .NET Framework 1.1. It is hosted on a web hosting service in the US. I am...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
11
by: Richard Myers | last post by:
Hello Im sure many of you have seen this error message before: For us its the third time this year. This error occurs seemingly at random. I have no idea what causes it too happen. None....
1
by: alex | last post by:
I can map all files (.*) to asp.net worker process. But that is a perfomance hit and default documents are no longer working. How do I map "NO FILE" to asp.net worker? Like if I have an url : ...
5
by: J-T | last post by:
I guess I'm a litte bit confused about app pool and worker process. In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process...
0
by: Gregory Gadow | last post by:
Still working on this project. What I have working: I have a service that uses FileSystemWatcher on an "in box" folder. When a text file appears in the in-box, it copies the file to a work...
13
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
6
by: sjoshi | last post by:
I'm able to use the Bacground Worker class to execute task and pain the UI. However I want to be able to execute n tasks in order, say n1, then n2 if there were no errors during n1, n3 so on. ...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.