Solved

Access Denied with Process.start when reading a text file.

Posted on 2010-08-27
10
518 Views
Last Modified: 2012-05-10
I'm trying to open a log file from an applications, I'm using the native listview control in vb.net in teh dblclick event the file path and name is correctly found, but when feeding to the start process function I get an 'Access is denied' error, any ideas?  The value of the file/path is i.e.

LogFilePaht = F:\Software Source Code\Virtual Web Software\Charlotte Burn Permit\bin\Debug\log_files\bp-8-24-2010.log

    Private Sub LogFileList_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles LogFileList.DoubleClick
        Dim LogFilePath As String = LogFileList.SelectedItems(0).ToString
        System.Diagnostics.Process.Start(LogFilePath)
    End Sub

Open in new window


.log is associated with a valid applications.
0
Comment
Question by:DRRobinson
  • 5
  • 4
10 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33545240
It looks like a permission issue.
Can you open that file from your Windows Explorer? Or Press Start->Run, copy/paste the file path/name in the box and hit OK. See if the file opens up.

0
 

Author Comment

by:DRRobinson
ID: 33545306
I don't think it's a permission issue.  I'm able to open the file just fine, and I was using a thrid party list box for the same function,but opted for the viewlist control that's native to VB.net so I would not have to distribute any third party contorls..
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33545319
Or try this:

System.Diagnostics.Process.Start("Notepad.exe", LogFilePath)
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 5

Expert Comment

by:jijeesh
ID: 33545739
What type of application you have this code?? Is it from a web application or a windows forms app?
If it is from ASP.NET page, you should grant enough permission to the ASP.NET user to the folder where you have file.
0
 

Author Comment

by:DRRobinson
ID: 33545827
It's a windows form app.  As mentioned it was working great when I used a third  pary list control, but when I switched to the native listview control I'm getting the error. when using the syntax:

System.Diagnostics.Process.Start("Notepad.exe", LogFilePath) does not work.

but I belive the syntax sould be

System.Diagnostics.Process.Start("Notepad.exe" -F LogFilePath)

Which does not work either...
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33545877
Add Chr(34) to LogFilePath, like this:

System.Diagnostics.Process.Start(Chr(34) & LogFilePath & Chr(34))

because there are spaces in the path.


0
 

Author Comment

by:DRRobinson
ID: 33545950
System.Diagnostics.Process.Start(Chr(34) & LogFilePath & Chr(34))

produces the error

No application is associated with the specified file for this operation - which is actually what I'm trying to do, I want to open the file in the program that is associated with the extension .log - in my case, it's not notepad, but ultraedit.
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33546078
One step closer...
You can either add association of the file type ".LOG" with ultraedit in Windows Explorer using Tools->Folder Options->File Type, add ".LOG" extension and Change to ultraedit in the "Open with",
or you need add ultraedit's full path in the code, like this:

System.Diagnostics.Process.Start(Chr(34) & "ultraedit Full Path" & chr(34), Chr(34) & LogFilePath & Chr(34))
0
 

Author Comment

by:DRRobinson
ID: 33546226
Not sure what the deal was, but I just changed the listview to a regular list box and it is now working.  I think that perhaps there was a comfilict with variable naming.  I have a global variable named 'LogFilePath', then I was using  a local variable:

Dim LogFilePath As String = LogFileList.SelectedItems(0).ToString

instead of creating a new object from the form (Dim fLog as new frmSelLog), which is what I normally do, I just opened the frmSelLog as .showdialog. Not sure, but it's working now.. not sure how to finalize this thread?
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33546283
Aha... I missed that part too. In listview, you should use this:
        Dim LogFilePath As String = LogFileList.SelectedItems(0).Text.ToString

0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

808 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