Web Forms :: File Being Locked By A Process?
Mar 10, 2010
I'm uploading an excel file and viewing it in a grid. But if I need to upload the file again in a couple of minutes I get an error that the file is being used by another process, so I cannot upload the file again. The file is always the same name.
View 3 Replies
Similar Messages:
May 7, 2015
after i can copy my file to another folder i realised that if this webapplication is used by multiple users at once, then some users are going to get locked out because each one is trying to copy those files.
so how do i tell the user thats trying to use a file to wait untill the file is available.
StreamWriter WriterTotxt = new StreamWriter("date.txt", false);
DateTime LastAccess = File.GetLastWriteTime("path.dbf");
WriterTotxt.Write(LastAccess);
WriterTotxt.Flush();
WriterTotxt.Close();
string ReadTextFile = File.ReadAllText(txtFile);
DateTime test = Convert.ToDateTime(ReadTextFile);
if (File.GetLastWriteTime(LatestUpdatedTime).CompareTo(test) > 0)
{
File.Copy(Path.Combine(sourcefile, fName), Path.Combine(destinationfile, fName), true);
}
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
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
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
Oct 17, 2010
I am trying to download a file from the server but i am getting this error:
The process cannot access xxxx the file because it is being used by another process
This is my CODE:
string fileName="DownLoadFiles";
string filePath = hid_filepath.Value;
FileInfo file = new FileInfo(filePath);
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile(new Uri(fileName, filePath);
Foe ur Information:the file is not opened or not used.
View 1 Replies
Jul 22, 2010
I have some pdf files that get attached to emails and are emailed out through a web application. Sometimes this causes the PDF files to get locked and I cannot delete them from the server (even after the email has gone out). I get the message "The process cannot access the file 'D:myfile.pdf' because it is being used by another process".
View 6 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
Sep 2, 2011
I have a web page in my project that views a selected pdf file. The problem is the file stays locked with the process w3wp.exe which I assume is the adobe file reader or something. How I can release this process after viewing it? Or another way of viewing it without locking the file?
Here is how I am doing it:
Code:
Dim File1 As String = System.Configuration.ConfigurationManager.AppSettings("Report")
Dim R1 As String = Page.Request.QueryString("r")
If R1 <> "" Then
Dim path As String = File1 & R1
[Code]..
View 1 Replies
Jun 14, 2010
I have a page where users can upload an excel file and it is read into our system. I am using the Jet.OLEDB.4.0 provider to read the files. I access the file one time to read out the header names and then allow the user to select which field each column will be read into on import. For some reason after this read the file is locked and the next time I try to access it to do the data import I get the "File in use" message. Each time I open a connection it is closed so I am not sure why the file is being locked.
View 2 Replies
Feb 10, 2010
When I delete all files from the directory path. then it will give me this error The process cannot access the file because it is being used by another process. How to solve this?
View 10 Replies
May 12, 2010
I have an asp.net website and I allready did .Dispose() here is my code below;
try
{
MailMessage newMail = new MailMessage(MailFrom, MailTo,
MailSubject, MailMsg);
if (MailAttachment != "")
{
Attachment data = new Attachment(MailAttachment,
MediaTypeNames.Application.Octet);
newMail.Attachments.Add(data);
}
newMail.BodyEncoding = System.Text.Encoding.UTF8;
newMail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("192.168.2.205");
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(newMail);
newMail.Attachments.Dispose();
newMail.Dispose();
DeleteAttachment(MailAttachment);
lblSuccess.Text = "Başvurunuz alınmıştır teşekkürler.";
lblSuccess.Visible = true;
ClearForm();
}
catch (Exception ex)
{
lblSuccess.Text = ex.Message;
//lblSuccess.Text = "Bir sorun oluştu bir daha deneyiniz.";
lblSuccess.Visible = true;
}
But i' m getting the same error, it' s running fine in my localhost but in server i' m getting this error. How can i fix it?
View 2 Replies
Feb 8, 2010
I am getting binary data from a SQL Server database field and am creating a document locally in a directory my application has permissions. However I am still getting the error specified in the title. I have tried numerous suggestions posted on the web including those suggested in previous posts on Stackoverflow. I have also used ProcessExplorer > Find Handle to locate the lock and it returns nothing as if the file is not locked.
I am using the code below to save the file to the file system and I then try to copy this file to a new location later in the application process within another method. It is this copy method that takes the path of the newly created file that throws the exception.
The file itself is created with its content and i can open it through Windows Explorer without any problems.
Am I missing something completely obvious? Am I creating the file correctly from the database?
// Get file from DB
FileStream fs = new FileStream(
"C:myTempDirectorymyFile.doc", FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter br = new BinaryWriter(fs);
br.Write("BinaryDataFromDB");
fs.Flush();
fs.Close();
fs.Dispose();
// Copy file
File.Copy(sourceFileName, destinationFilename, true);
View 7 Replies
Oct 5, 2010
Iam getting the above said error while Iam copying a file of relativelly Heavy say 130 MB.Below is the code which is giving the error.
System.IO.FileInfo FileInfo1 = new System.IO.FileInfo(filename1);
FileInfo1.CopyTo(strDestPath,true);
View 6 Replies
Feb 6, 2012
I am using a AsyncUpload(telerik), i am in a point where i am supposed to save the File to a certain Folder. First I check if the directory exist
Code:
Dim baseDire As String = Server.MapPath("~/MyFILES/")
If IO.Directory.Exists(baseDire & Request("Req_ID").ToString()) = False Then
IO.Directory.CreateDirectory(baseDire & Request("Req_ID").ToString())
End If
Because i am doing multiple Upload , i will have to loop through the items of the Upload control and save to a folder.
Code:
For Each file As UploadedFile In UploadPropDoc.UploadedFiles
Dim bytes(file.ContentLength - 1) As Byte
file.InputStream.Read(bytes, 0, file.ContentLength)
'Save the File to the disk
file.SaveAs(baseDire + file.GetName())
Next
Now when ever i debug this , when it comes to this line
Code:
file.SaveAs(baseDire + file.GetName())
I get an Error
The process cannot access the file because it is being used by another process.
I have removed the Readonly in the Folder that it supposed to write to and gave everyone permission , but still the error persist.
View 1 Replies
Aug 12, 2013
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then Dim dataSet1 As New DataSet dataSet1
Dim dataSet2 As New DataSet dataSet2 Dim dataSet3 As New DataSet dataSet3
Dim dataSets As New List(Of DataSet)() dataSets.Add(dataSet1) dataSets.Add(dataSet2) dataSets.Add(dataSet3)
Dim strout As String = Server.MapPath("test1.xls") DataSetsToExcel(dataSets, strout) End If End Sub
[Code]..
How to create each excel sheet non-editable (read only)
View 1 Replies
Sep 8, 2010
MailMessage msg = new MailMessage("dd@gmail.com", txtTo.Text, txtSubject.Text, txtMessage.Text);
MailAddress newcc = new MailAddress(txtFrom.Text);
msg.CC.Add(newcc);
[code]...
View 9 Replies
Apr 12, 2013
I have a project with C# ASP.Net. I should create a web site which has categories.There will be a button and textbox and when I click this button there will be created a new web page and button and what I wrote text box it will be new button's text. At the same time, this created button's text will saved at SQL Server.I tried a create new button on page load but when I execute the project the button was created but I want to create with another button.These are for buttons; and these are for a new web page;(but there is an error -->Sayac.txt is already using)
sayac =int.Parse(rdr.ReadLine())+1;
File.Copy(MapPath("_template.aspx"), MapPath("WebForm" + sayac + ".aspx"));
rdr.Close();
wrt = new StreamWriter(MapPath("sayac.txt"), false);
wrt.WriteLine(sayac);
wrt.Close();
View 1 Replies
Oct 11, 2010
I have a folder called GUI. Inside GUI thers another folder called PDF and inside this folder, there are some PDF files. This folder (GUI) is uploaded to the server too. Then I have a WebForm with some ImageButtons. When I click one of these ImageButtons, I want the file to open in a new tab. I tried with the following code:
[Code]....
As you can see, I build the path using the tooltips of the different ImageButtons. The ToolTip = File Name I want to open. When I try this in debug mode, it works. It opens the pdf file in a new tab. However when I publish my website and upload it to the server... it doesn't work... when I click an ImageButton I get the following exception: No application is associated with the specified file for this operation
Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation
Source Error:
[Code]....
Stack Trace:
[Code]....
[Win32Exception (0x80004005): No application is associated with the specified file for this operation]
LandingSite.LnkRelease1_Click(Object sender, EventArgs e) +215
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +118
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.3607; ASP.NET Version:2.0.50727.3082
View 3 Replies
Oct 28, 2010
I have a code that sends email using smtp server. There is an attachement file called test.pdf. the code is like this. This code is called from button Click event.
[Code]....
[Code]....
[Code]....
View 6 Replies
Jun 13, 2012
I have one gridview in that i have three columns "FileName" "Open" and "Delte" if user Opens clicks on open Pdf file opens in new window that time if user clicks on Delete Button then its giving Error that "Process is using by Some one" ...
View 1 Replies
Sep 23, 2010
currently we are configured execution Timeout="1200" (The default is 110 seconds) and maxRequestLength="12288" (The default is 4096 KB)but some times users upload files above 12MB so we are getting "Maximum request length exceeded" error.we are checking the file size using client side javascript ActiveXObject object. but ActiveXObject only works in IE not in others like mozilla,crome,..Jacescript Code are
[Code]....
how can i check the file size before uploading process with support all the browser.any posiblities for checking file size before server side script/object?
View 5 Replies
Jan 20, 2011
On my current project I have to accept 2 Excel spreadsheets that will be uploaded by clients, process them and create a download package based on this information. This process includes extracting data from the sheets, updating our databases and building several PDF files for the download package. This takes between 15 seconds to 2 minutes to complete, depending on the complexity of the request. Naturally, I want to show some kind of processing indicator rather than just leaving the user hanging while the page loads.
Here's the problem: How to show this processing indicator.
I have to do a full postback to upload the files so this eliminates several nice AJAX indicator methods (sponsoring users rejected the AJAX toolkit async file upload, saying it was confusing to them). If I process on any of the page events during the postback, the page doesn't load until the lengthy process is completed so the browser/site looks 'hung'.
Basically, I need some ideas on how to display a 'building your download' graphic while the lengthy process is working that will also work with a full postback.
View 4 Replies
Feb 2, 2011
I am using an httpapi and i get an xml output in return from that. I am newbie to this and dont know how to process the returned xml. Kindly advice how to use this online xml file into my application to display to the user . The format of xml file is as follows :-
[Code]....
View 1 Replies
Dec 24, 2010
I have Online Exam application when the user has completed his exam is write the question, answer and his result in the excel sheet and store it in server path. The admin has the option to reset the user ie the file gets deleted from the server. It works fine when Admin resets the file after some minutes but if Admin tries to reset the files in as soon as the exam is completed then i get the exception like "File Cannot be deleted since its used by another process" .
1. Will it work when i kill the Excel.exe in the server after the file completes the process or is there any optimul way to do the same.
View 1 Replies