Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# file unlock

Posted on 2014-02-17
6
Medium Priority
?
1,057 Views
Last Modified: 2014-02-20
Hi,
Please see below Code
string Filepath = @"C:\\Program Files (x86)\\test.log";  

 if (File.Exists(Filepath))
            {
             System.IO.StreamReader file1 =new System.IO.StreamReader(Filepath);
            
           

            while ((line = file1.ReadLine()) != null)
            {
                xx.Add( line);
             
                counter++;
                
            }

Open in new window


please see below my error,Could you kindly someone help me to solve this issue.
thx
Error-File.png
0
Comment
Question by:ukerandi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 total points
ID: 39866090
The file has been opened by another application, where it might still be in use, or by a previous run of your own application, and has not been closed properly. Contrary to some other systems, .NET does not automatically closes files, you need to explicitely do it yourself.

If it is opened in another application, then you have to close that application and hope that it will close the file properly.

Otherwise, you first need to reboot your computer to release the file.

Be sure to add a file.Close call before the end of your method. Also, be sure to catch all possible errors in a try...catch and Close the file if an error happens after the file has been opened.
0
 
LVL 10

Author Comment

by:ukerandi
ID: 39866100
i can't stop that runining that application.thats the why iam getting stuck,

basicaly someone write Exe file creating logs file, i need to read that file, i can copy but its not allowed to do that. without copy another folder i have to read within same folder.

Can you help me with suggestion or any idea
0
 
LVL 10

Author Comment

by:ukerandi
ID: 39866122
or show me how to Kill the Process

like Process pr=new Process();

pr.Kill

I don't know where to put Exe file.thx
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 10

Author Comment

by:ukerandi
ID: 39866156
iam using following code
Process[] runningProcesses = Process.GetProcesses();
            foreach (Process process in runningProcesses)
            {
                // now check the modules of the process
                foreach (ProcessModule module in process.Modules)
                {
                    if (module.FileName.Equals("RecordsSr.exe"))
                    {
                        process.Kill();
                    }
                }
            }

Open in new window

But Access denied , can any one help me?
0
 
LVL 10

Author Comment

by:ukerandi
ID: 39866160
iam login as Administrator
0
 
LVL 40
ID: 39875774
Can you kill the process through the Task Manager (Ctrl-Alt-Del)?
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question