473,749 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(obj ect sender, System.EventArg s e)
{
try
{
if (File.Exists(Se rver.MapPath(xm lDocPath+Projec tsDoc)))
{ ProjectTree.Dis pose();
File.Delete(Ser ver.MapPath(xml DocPath+Project sDoc));
}

}
catch(Exception ex)
{SetErrorMessag e(ex.Message.To String(),true);
}
}
private void InitializeTreeV iew()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.Tre eNodeSrc=
DataRetrieval.f ormatXMLforTree ("eacollin.Proj ectXML");

ProjectsDoc=Dat aRetrieval.Prep areProjectsXMLd oc("eacollin.Pr ojectXML");
ProjectTree.Tre eNodeSrc= Server.MapPath( xmlDocPath+Proj ectsDoc);
ProjectTree.Def aultStyle.CssTe xt="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.Dat aBind();
ProjectTree.Dis pose();
}

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
this.Unload+=ne w System.EventHan dler(this.Page_ UnLoad);
//ProjectTree.Unl oad+=new System.EventHan dler(this.Delet eXmlFiles);

}

public static string PrepareProjects XMLdoc(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.Strin gWriter strWriter = new StringWriter();
try
{
if(System.Web.H ttpContext.Curr ent.Cache["Projects"]==null)
{

ds = SqlHelper.Execu teDataset(Confi gurationSetting s.AppSettings[ASPNET.StarterK it.TimeTracker. Web.Global.CfgK eyConnString],
SPname);

strXML = "";
ds.WriteXml(str Writer);
strXML = strWriter.ToStr ing();

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

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

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

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

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

System.Web.Http Context.Current .Cache.Insert(" Projects",strXM L,null,
DateTime.Now.Ad dHours(HoursLef t),Cache.NoSlid ingExpiration);
}

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

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

using(StreamWri ter wr = new
StreamWriter(Sy stem.Web.HttpCo ntext.Current.S erver.MapPath(x mlDocPath+OutFi leName)))
{
wr.Write(strXML );
}
strWriter.Close ();

//return OutFileName;
}
catch(Exception ex)
{
System.Web.Http Context.Current .Response.Write (ex.Message);
}
return OutFileName;
}
Nov 18 '05 #1
3 2938
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********@hot mail.com> wrote in message
news:f2******** *************** *@posting.googl e.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(obj ect sender, System.EventArg s e)
{
try
{
if (File.Exists(Se rver.MapPath(xm lDocPath+Projec tsDoc)))
{ ProjectTree.Dis pose();
File.Delete(Ser ver.MapPath(xml DocPath+Project sDoc));
}

}
catch(Exception ex)
{SetErrorMessag e(ex.Message.To String(),true);
}
}
private void InitializeTreeV iew()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.Tre eNodeSrc=
DataRetrieval.f ormatXMLforTree ("eacollin.Proj ectXML");

ProjectsDoc=Dat aRetrieval.Prep areProjectsXMLd oc("eacollin.Pr ojectXML");
ProjectTree.Tre eNodeSrc= Server.MapPath( xmlDocPath+Proj ectsDoc);
ProjectTree.Def aultStyle.CssTe xt="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.Dat aBind();
ProjectTree.Dis pose();
}

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
this.Unload+=ne w System.EventHan dler(this.Page_ UnLoad);
//ProjectTree.Unl oad+=new System.EventHan dler(this.Delet eXmlFiles);

}

public static string PrepareProjects XMLdoc(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.Strin gWriter strWriter = new StringWriter();
try
{
if(System.Web.H ttpContext.Curr ent.Cache["Projects"]==null)
{

ds = SqlHelper.Execu teDataset(Confi gurationSetting s.AppSettings[ASPNET.StarterK it
..TimeTracker.W eb.Global.CfgKe yConnString], SPname);

strXML = "";
ds.WriteXml(str Writer);
strXML = strWriter.ToStr ing();

//get rid of the text version of < and > tags
strXML = Regex.Replace(s trXML, "&lt;", "<");
strXML = Regex.Replace(s trXML, "&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(s trXML,search,"" );

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

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

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

System.Web.Http Context.Current .Cache.Insert(" Projects",strXM L,null,
DateTime.Now.Ad dHours(HoursLef t),Cache.NoSlid ingExpiration);
}

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

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

using(StreamWri ter wr = new
StreamWriter(Sy stem.Web.HttpCo ntext.Current.S erver.MapPath(x mlDocPath+OutFi l
eName))) {
wr.Write(strXML );
}
strWriter.Close ();

//return OutFileName;
}
catch(Exception ex)
{
System.Web.Http Context.Current .Response.Write (ex.Message);
}
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******* *******@TK2MSFT NGP09.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********@hot mail.com> wrote in message
news:f2******** *************** *@posting.googl e.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(obj ect sender, System.EventArg s e)
{
try
{
if (File.Exists(Se rver.MapPath(xm lDocPath+Projec tsDoc)))
{ ProjectTree.Dis pose();
File.Delete(Ser ver.MapPath(xml DocPath+Project sDoc));
}

}
catch(Exception ex)
{SetErrorMessag e(ex.Message.To String(),true);
}
}
private void InitializeTreeV iew()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.Tre eNodeSrc=
DataRetrieval.f ormatXMLforTree ("eacollin.Proj ectXML");

ProjectsDoc=Dat aRetrieval.Prep areProjectsXMLd oc("eacollin.Pr ojectXML");
ProjectTree.Tre eNodeSrc= Server.MapPath( xmlDocPath+Proj ectsDoc);
ProjectTree.Def aultStyle.CssTe xt="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.Dat aBind();
ProjectTree.Dis pose();
}

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
this.Unload+=ne w System.EventHan dler(this.Page_ UnLoad);
//ProjectTree.Unl oad+=new System.EventHan dler(this.Delet eXmlFiles);

}

public static string PrepareProjects XMLdoc(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.Strin gWriter strWriter = new StringWriter();
try
{
if(System.Web.H ttpContext.Curr ent.Cache["Projects"]==null)
{

ds =

SqlHelper.Execu teDataset(Confi gurationSetting s.AppSettings[ASPNET.StarterK it
.TimeTracker.We b.Global.CfgKey ConnString],
SPname);

strXML = "";
ds.WriteXml(str Writer);
strXML = strWriter.ToStr ing();

//get rid of the text version of < and > tags
strXML = Regex.Replace(s trXML, "&lt;", "<");
strXML = Regex.Replace(s trXML, "&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(s trXML,search,"" );

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

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

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

System.Web.Http Context.Current .Cache.Insert(" Projects",strXM L,null,
DateTime.Now.Ad dHours(HoursLef t),Cache.NoSlid ingExpiration);
}

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

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

using(StreamWri ter wr = new

StreamWriter(Sy stem.Web.HttpCo ntext.Current.S erver.MapPath(x mlDocPath+OutFi l
eName)))
{
wr.Write(strXML );
}
strWriter.Close ();

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

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******* *******@TK2MSFT NGP09.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********@hot mail.com> wrote in message
news:f2******** *************** *@posting.googl e.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(obj ect sender, System.EventArg s e)
{
try
{
if (File.Exists(Se rver.MapPath(xm lDocPath+Projec tsDoc)))
{ ProjectTree.Dis pose();
File.Delete(Ser ver.MapPath(xml DocPath+Project sDoc));
}

}
catch(Exception ex)
{SetErrorMessag e(ex.Message.To String(),true);
}
}
private void InitializeTreeV iew()
{
//Add data to treeview based on the projectXML stored procedure
//ProjectTree.Tre eNodeSrc=
DataRetrieval.f ormatXMLforTree ("eacollin.Proj ectXML");

ProjectsDoc=Dat aRetrieval.Prep areProjectsXMLd oc("eacollin.Pr ojectXML"); ProjectTree.Tre eNodeSrc= Server.MapPath( xmlDocPath+Proj ectsDoc);
ProjectTree.Def aultStyle.CssTe xt="color: black;font-family:
verdana;font-size: 8pt;";
ProjectTree.Dat aBind();
ProjectTree.Dis pose();
}

private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
this.Unload+=ne w System.EventHan dler(this.Page_ UnLoad);
//ProjectTree.Unl oad+=new System.EventHan dler(this.Delet eXmlFiles);
}

public static string PrepareProjects XMLdoc(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.Strin gWriter strWriter = new StringWriter();
try
{
if(System.Web.H ttpContext.Curr ent.Cache["Projects"]==null)
{

ds =

SqlHelper.Execu teDataset(Confi gurationSetting s.AppSettings[ASPNET.StarterK it .TimeTracker.We b.Global.CfgKey ConnString],
SPname);

strXML = "";
ds.WriteXml(str Writer);
strXML = strWriter.ToStr ing();

//get rid of the text version of < and > tags
strXML = Regex.Replace(s trXML, "&lt;", "<");
strXML = Regex.Replace(s trXML, "&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(s trXML,search,"" );

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

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

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

System.Web.Http Context.Current .Cache.Insert(" Projects",strXM L,null, DateTime.Now.Ad dHours(HoursLef t),Cache.NoSlid ingExpiration);
}

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

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

using(StreamWri ter wr = new

StreamWriter(Sy stem.Web.HttpCo ntext.Current.S erver.MapPath(x mlDocPath+OutFi l eName)))
{
wr.Write(strXML );
}
strWriter.Close ();

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

return OutFileName;
}


Nov 19 '05 #4

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

Similar topics

1
1624
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 files cannot be opened and I receive an error. I have also seen occurances where for some reason VS.NET suffered a fatal error and shut down. When teying to open the files in /bin again after a reboot, I am unable to. I have come up with 3...
3
2837
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 experiencing the "Viewstate corrupted" error message on a particular page, when that page is left for a period of time and I return to it again, and submit it again. The page in question has a drop-down list of various RSS news feeds I am...
9
23083
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 to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
11
1817
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. Question 1: Do you?
1
1203
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 : http://domain/id1/id2/ When there is no file name in the url IIS checks for such dir and throws 404 BEFORE passing execution to asp.net worker.
5
3958
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 per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool then: 1) Can I have multiple worker processes assigned to that pool? If yes,what is the advantage of doing so?
0
1160
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 folder, processes it a bit, goes through a list of rules and applies the first one that fits. Based on the applied rule, the file can be printed, copied or deleted, or a user can be sent an email notification. I ran in to a problem where...
13
11153
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 writes a specific string to the log file. My original program (MKS Toolkit shell program) which keeps running "grep" checking the "exit string" on the "log files". There are no file sharing problem.
6
5963
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. I'm wondering what would be the best way to do this , do I wait in a do...while loop for each to finish and then start another ? thanks Sunit
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.