Get Process ID And Deal With It Using C#?
Feb 9, 2010
If one file is used by other process and you are trying to manipulate with it...it gives an error:-
The process cannot access the file 'abc.txt' because it is being used by another process.
In C#, How can i come to know that 'abc.txt' file is used by the process Name "XYZ.exe" (or any other process)?
View 1 Replies
Similar Messages:
Sep 7, 2010
I've written a aspx.net(C#) page that after the user has done what they do on the page they hit a Submit button. The Submit button
1) takes the work the users was producing on the page and writes it to a file.
2) attempts to execute a batch file.
The call to the batch file is executed via:
protected void Execute123EDI()
{
try
{
string File = @"c:80sAdminSendV80s.bat";
lblCancelled.Text = lblCancelled.Text + File;
Process proc = new System.Diagnostics.Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.LoadUserProfile = false;
proc.StartInfo.UserName = "administrator";
proc.StartInfo.RedirectStandardOutput = true;
System.Security.SecureString secPass = new System.Security.SecureString();
string paswd = "123abc";
for (int i = 0; i < paswd.Length; i++)
{
secPass.AppendChar(paswd[i]);
}
proc.StartInfo.Password = secPass;
proc.StartInfo.FileName = File;
proc.Start();
FileStream fs = new FileStream(@"c:80sAdminSendV80sOutput.log", FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
sw.Write(proc.StandardOutput.ReadToEnd());
proc.WaitForExit();
sw.Close();
proc.Close();
}
catch(Exception ex)
{
lblDebug.Text = lblDebug.Text + ex.Message + "<br/>";
}
If I watch the processes tab in Task Manager on the web server I see "cmd.exe" under the context of 'administrator' but it just hangs. For test purposes c:SendV80s.bat: copy c: oot.ini c:zzz.txt
If I logon onto the webserver's console and execute SendV80s.bat it works and exits without issue. But when I execute the same batch file via the Submit button it gets stuck executing in Task Manager/Process. I believe this has something to do with the fact that cmd is not running in a full environment/desktop context. I just noticed this on the actual console of the webserver (not in my RDP console but console 0 instead)
A pop-up box stating: CMD.exe Application error The application failed to initialize properly (0xc0000142). Click OK to terminate the application. And when I click on the OK button my ASPX page's WaitForExit is satisfied and the continues processing normally.
View 2 Replies
Apr 13, 2010
this is my requirement
1 receive an xml string
2 data procress (retrieve data from db ãupdata from db ... )
3 return an result of xml string
this the way I did
1 receive an xml string
2 parse xml by this way
string NO = xml.GetElementByTat("NO")[0].InnerText;
string Name = xml.GetElementByTat("Name")[0].InnerText;
use data to active with Database
ex: select Manager from deparement where EMPNo = 'No' and EMPNAME = 'NAME'
3 return an result xml to the who call webservice
string rtnXml = "<ProjectTeam>"
+"<No>A121</NO>"
+"<Name>Jack</Name>"
+"<Manager>Allen</Manager>"
+"</ProjectTeam>";
like this... but sometimes this way is mass.. do you have other idea to deal with xml ?
View 3 Replies
Jul 21, 2010
I know that similar questions have been asked all over the place, but I'm having trouble finding one that relates directly to what I'm after.
I have a website where a user uploads a data file, then that file is transformed and imported into SQL. The file could be up to 50mb in size, and some times this process can take 30 minutes or sometimes even longer.
I realise I need to palm off the actual work to another process, and poll that process on the web page. I'm wondering what the best approach would be though? Being a web developer by trade, I'm finding all this new Windows Service stuff a bit confusing, and I just wanted somewhere to start.
So:
Can I do / should I being doing this with a windows service? if so, how?
Should I use WCF? If this runs under IIS, will I have problems with aspnet_wp.exe recycling and timing out my process?
clarifications
The data is imported into sql, there's no file distribution taking place.
If there is a failure, it absolutely MUST be reported to the user. The web page will poll every, lets say, 5 seconds, from the time the async task begins, to get the 'status' of the import. Once it's finished another response will tell the page to stop polling for status updates.
queries on final decision
ok, so as I thought, it seems that a windows service is the best idea. So as to HOW to get it to work, it seems the 'put the file there and wait for the service to pick it up' idea is the generally accepted way, is there a way I can start a process run by the service, without it having to constantly be checking a database table / folder? As I said earlier, I don't have any experience with Windows Services - I wondered if I put a public method in the service, can I call it somehow?
View 2 Replies
Feb 26, 2010
I'm working on an ASP.net app I'm trying to execute a process remotely , using System.Diagnostics.Process class here's my code:
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:TestCommand.exe");
startInfo.Domain = "myDomain";
startInfo.UserName = "MyUserName";
SecureString sec = new SecureString();
foreach (char item in "MyPassword")
{
sec.AppendChar(item);
}
sec.MakeReadOnly();
startInfo.Password = sec;
startInfo.UseShellExecute = false;
Process.Start(startInfo);
I keep receiving an exception with the message "Logon failure: unknown user name or bad password". Im absolutelly sure that i'm submiting my correct username/pwd
View 1 Replies
Apr 3, 2010
I've developed a popup email .aspx used on our intranet based web app that is auto generated with .pdf's attached. I'm developing with VS 2008 ASP.Net 3.5 C# and System.Net.Mail.MailMessage. I can create and send the email with no issues. The problem is with any attempt to open or delete the attachments I get the above error. The .pdf's a copied with the following code:
FileStream fsr = new FileStream(inFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader reader = new BinaryReader(fsr);
byte[] bytes = new byte[fsr.Length];
reader.Read(bytes, 0, bytes.Length);
FileStream fsw = new FileStream(outFileName, FileMode.Create, FileAccess.Write, FileShare.Write);
BinaryWriter writer = new BinaryWriter(fsw);
writer.Write(bytes, 0, bytes.Length);
// clean up
writer.Flush();
writer.Close();
writer = null;
fsw.Close();
fsw.Dispose();
fsw = null;
reader.Close();
reader = null;
fsr.Close();
fsr.Dispose();
fsr = null;
Later after sending the email I:
mailMessage.Dispose();
mailMessage = null;
foreach (string fileName in attachments)
{
if (File.Exists(fileName))
File.Delete(fileName);
}
The error occurs at: the File.Delete(fileName);
how I can delete or reopen these files after sending the email?
View 9 Replies
Jan 14, 2011
I have two tables that effectively have a many to many relationship between them. Effectively I want to perform a query that returns results just from Table2. For simplisity table2 has 4 fields: theId, ForeignId, Info, extra
In table2 there can be multiple records with the same value of ForeignId (but each will have a unique theId which is the tables primary key).
I want to perform a:
select top (1) * where ForeignId=x order by extra
which will select 1 record for a given ForeignId
However, I then want to wrap that within an outer query where I have a list of foreignId (ie where ForeignId in ListOfX) but I want to return 1 result record for each value of foreignId. Does that make sense? So the result will be a set of records with one record for each value of foreignId and that record would have 'info' from the top(1) record from the inner query.
View 3 Replies
Mar 8, 2011
ite on dataset model and I used to write sql quires into dataset and call them with in my c# code as usual. and used the datatablein c#code to access the values of each column which corresponds to a sql column in the sql table. after a while I found my website going on too slowso I decided to use linq to sql classes. i can write queries in c# code
[Code]....
View 4 Replies
Jan 26, 2011
I want my Data Access Layer to be built very modular.Therefore I have data retrieval methods that sometimes are called directly from the business layer and sometimes are called by other data retrieval methods to create object dependencies.What is the best way to deal with database connections in the DAL?
a) Create a new connection in every method and dispose it afterwards.Good: Easy to write and to work with.
Bad: Many connections are being opened and closed. (performance?)
b) Pass the connection as an (optional) argument.Good: I could reuse an open connection for multiple commands.Bad: I have to keep track of the ownership of the connection (who has to close it?) and cannot use the very neat "using" statements.c) Something else? (Connection as singleton maybe?)This is the first time I am writing a real DAL so I really could use some help from you experienced folks.EDIT: As it seems to matter, it's an ASP.Net Website Project.
View 5 Replies
Mar 17, 2010
I use the following string format to navigate between webpages:
String.Format(Eval("Hyper") + "?BUSINESSSTREAM={0}&Dealer={1}&LeadID={2}&Companyid={3}&SalesPerson={4}", Eval("BusinessStream"), Eval("Dealer"),Eval("leadId"),Eval("CompanyID"),Eval("SalesPerson"))
However the companyid is a text string and the company may have an "&" in it which I know will truncate the string. I have seen that this can be overcome by using "UrlEncode" [URL] However I cant solve the syntax.
View 10 Replies
Mar 27, 2011
I'm trying to import a few hundreds of data to a SQL server database table from Excell Spreedsheet. In the taable, I created Id as key that is identity. How can I solve identity when I import excel data to the database table.
View 3 Replies
Sep 8, 2010
I recognized that based on a context in which I want to use some parameters, there are at least 4 kinds of encoding that are necessary to avoid corrupted code being executed :
Javascript encoding when constructing a javascript code, e.g.
var a = "what's up ?"
var b = "alert('" + a + "');"
eval(b); // or anything else that executes b as code
[Code]....
View 3 Replies
Dec 25, 2010
Dear ladies and sirs.
I have a .NET infra code running both within the IIS worker process and within a desktop client app. How can the .NET code determine whether it is running within an IIS worker process?
I know that I could check the name of the process (w3wp.exe, for instance), but I would like a more robust approach. I wish to make a side note. This is not a production need. I need this information to enable certain scenarios useful during the development and testing phase. Specifically to ease the testing of secure vs non secure configurations.
View 3 Replies
Jan 26, 2010
When I hit the run button (in my Default.aspx), a process starts (this process contacts a webservice to get some files, etc). How do I: Ensure that only a single process is running at a time (i.e. if I refresh the browser, I don't want to start the process a second time)Track progress - there are 4 points of the process (at 25%, 50%, 75%, 100%) that I want to track, and when each part completes, I want to update the progress bar. I have a status object for the running process, but the question is how to update the progress bar automatically? Do I need to use threads to achieve the above two?
View 1 Replies
Nov 6, 2010
My code is that I want to create a log file and log it upon a new user browsing the site. However, what i did was I put in a 6 second delay and then used another browser to access the page. And it threw an Exception saying it is being used by another process which is true. So how come I set it so that, if IT is being used by another process, WAIT and retry every 500 milliseconds until it becomes free/available?
here's the code:
protected void Page_Load(object sender, EventArgs e)
{if (!IsPostBack) // if this is the first time page loads, set k to 1
{ lognewuser();
}}
[Code]....
View 1 Replies
Mar 28, 2011
I am having the text file which is used to track all the ip address which is available in the network and replace the content from"Reply from 172.29.116.3: bytes=32 time=1ms TTL=255" to 172.29.116.3.
For this task i am having 2 functions 1.runCMD() Function is used to create a file which ping all the ip address between 3 to 254 ("Reply from 172.29.116.3: bytes=32 time=1ms TTL=255").
2.Another function textFileReplace() which is used to replace the text from "Reply from 172.29.116.3: bytes=32 time=1ms TTL=255" to 172.29.116.3.
This process will continue every 30 minutes..
But i am having the error while accessing the function textFileReplace() as The process cannot access the file 'C:inetpub' because it is being used by another process.
View 4 Replies
Mar 8, 2011
I am developing a web application which will deal with online examination. The requirement is:
There can be n-number of sections in an exam and admin users should be able to create questions/answers and add to an exam. The questions should be displayed for a certain amount of time in the browser with meclock and it should move to next question automatically. User should not be allowed to open any other instance of the browser or login from another IP if the exam is in progress.
I am seeking community vote of how would someone design the application to meet all these criterias? What patterns should be used? What components to reduce the development time etc..My technology stack is C#, ASP.NET MVC or ASP.NET with SQL Server.
View 3 Replies
Jul 15, 2010
I have a toolkit tabbed container with an update panel in the bottom of each of the tabbed container's content template. There is also a radio button list an, a text box and a button. The user chooses the search criteria with the radio button list. They then enter the search text in the text box and hit the search button.
The update panel is then going to display the appropriate grid view and results, depending on what radio button was chosen. The logic to check the radio buttons is in the click event of the search button. I currently have one of the grid views and set it's visible property to true in the logic that checks to see which of the radio buttons was selected. My plan so far is to continue adding the other gridviews and doing this the same way with them. This will toggle the correct Grid View on.
I'm wondering if there is a better way of dealing with the Grid Views. There will be one of three to be displayed with in this update panel. They will have different result sets from different tables. Is my approach for turning them off and on with the visible property a bad idea? Should I be doing all of the ODS and grid view stuff programmatically? Is there a better way of doing this?
View 2 Replies
Feb 2, 2010
I have a problem.when i create a new web site and browse it with IE8 ,there is error(Internet Explorer cannot display the webpage) and now i am working with VS2008 and IE8.but i also have an older version of VS(VS2005) on the same computer.when i created a new web page with 2005 ,there is no problem and everything is ok. what is the problem with VS2008??i uninstalled it and reinstalled.but there is same error.i tried VS2008 on the another computer and i had no problem.
View 2 Replies
Nov 30, 2010
I'm working on a pretty basic little site that has content that is populated from a sql database. It's important to know that the data in sql includes some html (bolds, italics, ordered lists,etc). The problem I'm running into, involves the search results. On the search results page, I display the results from a sql query in a gridview. The sql query only returns the first 200 characters of the "Description" field, and then there is a link to click if the user wants to read the full description. The problem I'm running into is when the gridview tries to format the data that has an opening html tag, but no closing html tag (becasue the closing tag is over the 200 character limit.
[Code]....
View 4 Replies
Jun 3, 2010
I have a dictionary in my user's view model used to store user's roles:
[Code]....
In my edit view:
[Code]....
the code above generates:
[Code]....
It seems that when I edited the checkboxes' value and post to server, the UserEditViewModel.Roles is empty.
View 2 Replies
Jun 26, 2010
I have some fields in my db that have a value of "NULL". These are displayed in the Data controls as "NULL". When I try to commit an update the Regex validator is catching this and not allowing the update because it doesn't match the pattern of the regex.
I've thought of one way of solving this, which is to add the value "NULL" to the pattern for the regex. I'm curious though if there is a better way to solve this issue.
View 3 Replies
Feb 2, 2010
I have 3 tables. Blog and Tag have a many to many relationship. BlogTag is a junction table with a quantity column.
**Blog**
BlogID
Title
**Tag**
TagID
Name
**BlogTag**
BlogID
TagID
Quantity
I'm not sure how I handle the quantity column. I'd like it to store how many Blogs have a certain Tag NameHow do I deal with the quantity column when adding a new blog that has tags?
View 1 Replies
Jun 10, 2010
I need to write a sql script which will scan for records in a table (Table1) and thencopy the records found into a second table (Table2). Table2 has the same table structureas Table1Table 1 has a primary Key for the first column named CustIdI thought this would involve A simple sql statement like:
INSERT INTO Table2
FROM Table1
SELECT *
However I just realized that if A record already exists in Table2 and I try to inserta duplicate record into Table2, how should this be handled?Should I instead use an Update statement without a where clause?
View 2 Replies
Dec 31, 2010
I don't like asp.net profile provider store all profile info in one or two row in the database, but I want to use membership/profile API for authentication purpose.Customize membership/role/profile provider requires big big upfront efforts, which may cause more mess later.So how do people deal with that normally?
View 2 Replies