tags:

views:

43

answers:

2

Hello Experts, I have a very simple VB.net Windows Service written using VS.net 2008. The program after doing several other functions writes a log in one of the network folders. The code is as shown below: If I change the path from "Y:\Activity_Log" to "C:\Activity_Log" it is working like a charm.

What is the problem if I use Y drive which is a valid one and I am able to access it from other VB.net desktop apps. Please help.

Dim strFile As String = "Y:\Activity_Log\" & DateTime.Today.ToString("dd-MMM-yyyy") & ".txt"
        Dim fs As FileStream = Nothing
        Dim activityfolder As String = "Y:\Activity_Log"
        Dim di As System.IO.DirectoryInfo

        di = New System.IO.DirectoryInfo(activityfolder)

        If (Not di.Exists) Then
            di.Create()
        End If


        If (Not File.Exists(strFile)) Then
            Try
                Dim sw1 As New StreamWriter(File.Open(strFile, FileMode.OpenOrCreate))
                sw1.WriteLine("******************************Activity Log for " & Now.Date & "*******************")
                sw1.WriteLine("-----------------------------------------------------------------------------------------------------------------")
                sw1.WriteLine(Remarks & " ---" & DateTime.Now)
                sw1.Close()
            Catch ex As Exception

            End Try

        Else
            Dim sw As StreamWriter
            sw = AppendText(strFile)
            sw.WriteLine(Remarks & " ---" & DateTime.Now)
            sw.Close()

        End If
+3  A: 

maybe you need to run the service under a user that has access to that drive?

maybe the generic service user doesn't have access.

Fredou
Fredou, Right now the service is running on my machine. Even then it is not able to access the network drive.
acadia
The service probably runs under a different user. You will want to make sure that the permissions for the mapped drive are set up to be visible for everybody.
Paul Lammertsma
+4  A: 

Start->Control Panel->Administrative Tools->Services

Find Your service in the list, right click on the name, Properties

Click the Log On tab

Change from Local System account to 'This Account'

Use a user that has access to that share, start with your username/password to convince yourself that it works ;)

Click Ok, then restart the service.

Sean
Sean, Thanks for your suggestion. I did specify the login details and restarted the service. It is still not working. Not just this network folder but none. I would really appreciate if you can suggest any solution for this.
acadia
Log the exception it is throwing to the eventviewer or a file, so you can figure out why access is being denied. I would assume it is probably just permission related.
Sean