Showing posts with label copy. Show all posts
Showing posts with label copy. Show all posts

Wednesday, March 28, 2012

System.IO.Directoryinfo throwing exception

I have an aspx page that is set up to copy backed-up DB files from a shared
directory to a local folder. For some reason, it is being denied access to
the network share. I have the web app running under a domain account that I
know for a fact has access. it works fine when I log on to the network and
browse the directory manually. Even when I grant full control to everyone on
the share and the underlying folder itself, I still can't access it through
code. The funny thing is though, this same code works fine when executed
within a windows service which runs under the same domain account. Help!
Code follows:
**** this first line is the one throwing the exception ********
Dim objFromDirectory As DirectoryInfo = New
DirectoryInfo("\\[server]\[network share]
Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
Dim objToDirectory As DirectoryInfo = New
DirectoryInfo(strNewBackupPath)
Dim objOldBackupFiles() As FileInfo =
objToDirectory.GetFiles()
Dim objNewBackupFiles() As FileInfo =
objFromDirectory.GetFiles()
Dim x As Integer
Dim intNewBackupFileCount As Integer =
UBound(objNewBackupFiles)
Dim objCurrentFile As FileInfo
Dim objBackUpLog As XmlDocument = New XmlDocument
Dim objNewParentNode As XmlElement
Dim objRootNode As XmlElement
Dim objLogEntryDateNode As XmlElement
Dim objNewChildNode As XmlElement
Dim objDateNodeList As XmlNodeList
Dim strStartTime As String
Dim strEndTime As String
Dim intFileSize As Integer = 0
Dim intLogEntryCount As Integer
Dim strBackUpLogPath As String =
"C:\SQLBackUp\SQLBackupLog.xml"
Dim objCurrentDateNode As XmlElement
Try
strStartTime = DateTime.Now.ToLongTimeString()
'-- delete old set of backups. GV 1/28/05
If UBound(objOldBackupFiles) > 0 Then
For x = 0 To UBound(objOldBackupFiles)
File.Delete(objOldBackupFiles(x).FullName)
Next
End If
'-- copy new set of backups. GV 1/28/05
'- if no backup files are found, throw an exception. GV
6/2/05
If intNewBackupFileCount < 1 Then
Throw New ApplicationException("No files were found.")
Else
For x = 0 To intNewBackupFileCount
objCurrentFile = objNewBackupFiles(x)
intFileSize = intFileSize + objCurrentFile.Length
objCurrentFile.CopyTo(strNewBackupPath & "\" &
objCurrentFile.Name)
Next
End If
strEndTime = DateTime.Now.ToLongTimeString()
'-- write file-copy info to XML log. GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)
' time started
objNewChildNode = objBackUpLog.CreateElement("starttime")
objNewChildNode.InnerText = strStartTime
objNewParentNode.AppendChild(objNewChildNode)
' time ended
objNewChildNode = objBackUpLog.CreateElement("endtime")
objNewChildNode.InnerText = strEndTime
objNewParentNode.AppendChild(objNewChildNode)
' total amount copied (in megs)
objNewChildNode = objBackUpLog.CreateElement("dataamount")
objNewChildNode.InnerText = CStr(Math.Round(intFileSize
/ 1048576, 2) & " Mb")
objNewParentNode.AppendChild(objNewChildNode)
' total number of files copied
objNewChildNode = objBackUpLog.CreateElement("nbroffiles")
objNewChildNode.InnerText = CStr(intNewBackupFileCount +
1)
objNewParentNode.AppendChild(objNewChildNode)
'-- delete entries older than 4 months. GV 1/31/05
objDateNodeList =
objBackUpLog.SelectNodes("/log/logentry/date")
For Each objCurrentDateNode In objDateNodeList
If DateValue(CDate(objCurrentDateNode.InnerXml)) <
DateValue(DateAdd("d", -120, DateTime.Now)) Then
objCurrentDateNode.RemoveAll()
objRootNode =
objCurrentDateNode.ParentNode.ParentNode
objRootNode.RemoveChild(objCurrentDateNode.ParentNode)
End If
Next
'-- save changes. GV 1/31/05
objBackUpLog.Save(strBackUpLogPath)
intOperationSuccess = 1
Catch exc As Exception
'-- if exception occurs, write error info to XML log.
GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)
' error header
objNewChildNode =
objBackUpLog.CreateElement("errorheader")
objNewChildNode.InnerText = "** ERROR **"
objNewParentNode.AppendChild(objNewChildNode)
' error description
objNewChildNode =
objBackUpLog.CreateElement("errordescription")
objNewChildNode.InnerText = exc.Message.ToString
objNewParentNode.AppendChild(objNewChildNode)
objBackUpLog.Save(strBackUpLogPath)
objEventLog.WriteEntry("**** ERROR **** " &
exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
intOperationSuccess = 0
'--
Finally
'-- destroy all objects. GV 1/28/05
x = Nothing
intFileSize = Nothing
intLogEntryCount = Nothing
If Not (objBackUpLog Is Nothing) Then objBackUpLog =
Nothing
If Not (objCurrentFile Is Nothing) Then objCurrentFile =
Nothing
intNewBackupFileCount = Nothing
If Not (objNewBackupFiles Is Nothing) Then
objNewBackupFiles = Nothing
If Not (objOldBackupFiles Is Nothing) Then
objOldBackupFiles = Nothing
If Not (objToDirectory Is Nothing) Then objToDirectory =
Nothing
If Not (strNewBackupPath Is Nothing) Then
strNewBackupPath = Nothing
If Not (objFromDirectory Is Nothing) Then
objFromDirectory = Nothing
If Not (strStartTime Is Nothing) Then strStartTime =
Nothing
If Not (strEndTime Is Nothing) Then strEndTime = Nothing
If Not (objRootNode Is Nothing) Then objRootNode = Nothing
If Not (objNewParentNode Is Nothing) Then
objNewParentNode = Nothing
If Not (objNewChildNode Is Nothing) Then objNewChildNode
= Nothing
If Not (objDateNodeList Is Nothing) Then objDateNodeList
= Nothing
If Not (objCurrentDateNode Is Nothing) Then
objCurrentDateNode = Nothing
If Not (objLogEntryDateNode Is Nothing) Then
objLogEntryDateNode = Nothing
If Not (strBackUpLogPath Is Nothing) Then
strBackUpLogPath = Nothing
'--
End TryAnother MVP has written a great article about this
http://west-wind.com/weblog/posts/1572.aspx
The crux is (and its a pain to get working) that using Anonymous
authentication (so no impersonation) the local ASPNET account has to have
the same credentials (username and password) on both machines in order to
delegate security. With basic authentication and impersonation you need to
use a domain account which can delegate and you can check how to mark your
impersonated account able to use security delegation here:
http://msdn.microsoft.com/library/d...>
NetHT05.asp.
This is also required if you want to use NTLM authentication over kerberos
Personally, I would implement a the remote server as an http device and use
http requests, checking the referrer whihc makes life a lot simpler than
using mapped network drives.
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>I have an aspx page that is set up to copy backed-up DB files from a shared
> directory to a local folder. For some reason, it is being denied access to
> the network share. I have the web app running under a domain account that
> I
> know for a fact has access. it works fine when I log on to the network and
> browse the directory manually. Even when I grant full control to everyone
> on
> the share and the underlying folder itself, I still can't access it
> through
> code. The funny thing is though, this same code works fine when executed
> within a windows service which runs under the same domain account. Help!
> Code follows:
> **** this first line is the one throwing the exception ********
> Dim objFromDirectory As DirectoryInfo = New
> DirectoryInfo("\\[server]\[network share]
>
> Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> Dim objToDirectory As DirectoryInfo = New
> DirectoryInfo(strNewBackupPath)
> Dim objOldBackupFiles() As FileInfo =
> objToDirectory.GetFiles()
> Dim objNewBackupFiles() As FileInfo =
> objFromDirectory.GetFiles()
> Dim x As Integer
> Dim intNewBackupFileCount As Integer =
> UBound(objNewBackupFiles)
> Dim objCurrentFile As FileInfo
> Dim objBackUpLog As XmlDocument = New XmlDocument
> Dim objNewParentNode As XmlElement
> Dim objRootNode As XmlElement
> Dim objLogEntryDateNode As XmlElement
> Dim objNewChildNode As XmlElement
> Dim objDateNodeList As XmlNodeList
> Dim strStartTime As String
> Dim strEndTime As String
> Dim intFileSize As Integer = 0
> Dim intLogEntryCount As Integer
> Dim strBackUpLogPath As String =
> "C:\SQLBackUp\SQLBackupLog.xml"
> Dim objCurrentDateNode As XmlElement
> Try
> strStartTime = DateTime.Now.ToLongTimeString()
> '-- delete old set of backups. GV 1/28/05
> If UBound(objOldBackupFiles) > 0 Then
> For x = 0 To UBound(objOldBackupFiles)
> File.Delete(objOldBackupFiles(x).FullName)
> Next
> End If
> '-- copy new set of backups. GV 1/28/05
> '- if no backup files are found, throw an exception. GV
> 6/2/05
> If intNewBackupFileCount < 1 Then
> Throw New ApplicationException("No files were
> found.")
> Else
> For x = 0 To intNewBackupFileCount
> objCurrentFile = objNewBackupFiles(x)
> intFileSize = intFileSize +
> objCurrentFile.Length
> objCurrentFile.CopyTo(strNewBackupPath & "\" &
> objCurrentFile.Name)
> Next
> End If
> strEndTime = DateTime.Now.ToLongTimeString()
> '-- write file-copy info to XML log. GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' time started
> objNewChildNode =
> objBackUpLog.CreateElement("starttime")
> objNewChildNode.InnerText = strStartTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' time ended
> objNewChildNode = objBackUpLog.CreateElement("endtime")
> objNewChildNode.InnerText = strEndTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' total amount copied (in megs)
> objNewChildNode =
> objBackUpLog.CreateElement("dataamount")
> objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> / 1048576, 2) & " Mb")
> objNewParentNode.AppendChild(objNewChildNode)
> ' total number of files copied
> objNewChildNode =
> objBackUpLog.CreateElement("nbroffiles")
> objNewChildNode.InnerText = CStr(intNewBackupFileCount
> +
> 1)
> objNewParentNode.AppendChild(objNewChildNode)
> '-- delete entries older than 4 months. GV 1/31/05
> objDateNodeList =
> objBackUpLog.SelectNodes("/log/logentry/date")
> For Each objCurrentDateNode In objDateNodeList
> If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> DateValue(DateAdd("d", -120, DateTime.Now)) Then
> objCurrentDateNode.RemoveAll()
> objRootNode =
> objCurrentDateNode.ParentNode.ParentNode
> objRootNode.RemoveChild(objCurrentDateNode.ParentNode)
> End If
> Next
> '-- save changes. GV 1/31/05
> objBackUpLog.Save(strBackUpLogPath)
> intOperationSuccess = 1
> Catch exc As Exception
> '-- if exception occurs, write error info to XML log.
> GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewParentNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' error header
> objNewChildNode =
> objBackUpLog.CreateElement("errorheader")
> objNewChildNode.InnerText = "** ERROR **"
> objNewParentNode.AppendChild(objNewChildNode)
> ' error description
> objNewChildNode =
> objBackUpLog.CreateElement("errordescription")
> objNewChildNode.InnerText = exc.Message.ToString
> objNewParentNode.AppendChild(objNewChildNode)
> objBackUpLog.Save(strBackUpLogPath)
> objEventLog.WriteEntry("**** ERROR **** " &
> exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> intOperationSuccess = 0
> '--
> Finally
> '-- destroy all objects. GV 1/28/05
> x = Nothing
> intFileSize = Nothing
> intLogEntryCount = Nothing
> If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> Nothing
> If Not (objCurrentFile Is Nothing) Then objCurrentFile
> =
> Nothing
> intNewBackupFileCount = Nothing
> If Not (objNewBackupFiles Is Nothing) Then
> objNewBackupFiles = Nothing
> If Not (objOldBackupFiles Is Nothing) Then
> objOldBackupFiles = Nothing
> If Not (objToDirectory Is Nothing) Then objToDirectory
> =
> Nothing
> If Not (strNewBackupPath Is Nothing) Then
> strNewBackupPath = Nothing
> If Not (objFromDirectory Is Nothing) Then
> objFromDirectory = Nothing
> If Not (strStartTime Is Nothing) Then strStartTime =
> Nothing
> If Not (strEndTime Is Nothing) Then strEndTime =
> Nothing
> If Not (objRootNode Is Nothing) Then objRootNode =
> Nothing
> If Not (objNewParentNode Is Nothing) Then
> objNewParentNode = Nothing
> If Not (objNewChildNode Is Nothing) Then
> objNewChildNode
> = Nothing
> If Not (objDateNodeList Is Nothing) Then
> objDateNodeList
> = Nothing
> If Not (objCurrentDateNode Is Nothing) Then
> objCurrentDateNode = Nothing
> If Not (objLogEntryDateNode Is Nothing) Then
> objLogEntryDateNode = Nothing
> If Not (strBackUpLogPath Is Nothing) Then
> strBackUpLogPath = Nothing
> '--
> End Try
>
Problem solved! All I had to do was set "identity impersonate" to "true" in
my web.config. Thank you so much!
"John Timney (ASP.NET MVP)" wrote:

> Another MVP has written a great article about this
> http://west-wind.com/weblog/posts/1572.aspx
> The crux is (and its a pain to get working) that using Anonymous
> authentication (so no impersonation) the local ASPNET account has to have
> the same credentials (username and password) on both machines in order to
> delegate security. With basic authentication and impersonation you need t
o
> use a domain account which can delegate and you can check how to mark your
> impersonated account able to use security delegation here:
> http://msdn.microsoft.com/library/d...
ecNetHT05.asp.
> This is also required if you want to use NTLM authentication over kerberos
> Personally, I would implement a the remote server as an http device and us
e
> http requests, checking the referrer whihc makes life a lot simpler than
> using mapped network drives.
> --
> Regards
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>
>
glad your sorted :)
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:CCC31167-8012-4FC7-9EC7-3F125F515339@.microsoft.com...
> Problem solved! All I had to do was set "identity impersonate" to "true"
> in
> my web.config. Thank you so much!
> "John Timney (ASP.NET MVP)" wrote:
>

System.IO.Directoryinfo throwing exception

I have an aspx page that is set up to copy backed-up DB files from a shared
directory to a local folder. For some reason, it is being denied access to
the network share. I have the web app running under a domain account that I
know for a fact has access. it works fine when I log on to the network and
browse the directory manually. Even when I grant full control to everyone on
the share and the underlying folder itself, I still can't access it through
code. The funny thing is though, this same code works fine when executed
within a windows service which runs under the same domain account. Help!

Code follows:

**** this first line is the one throwing the exception ********
Dim objFromDirectory As DirectoryInfo = New
DirectoryInfo("\\[server]\[network share]

Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
Dim objToDirectory As DirectoryInfo = New
DirectoryInfo(strNewBackupPath)
Dim objOldBackupFiles() As FileInfo =
objToDirectory.GetFiles()
Dim objNewBackupFiles() As FileInfo =
objFromDirectory.GetFiles()
Dim x As Integer
Dim intNewBackupFileCount As Integer =
UBound(objNewBackupFiles)
Dim objCurrentFile As FileInfo
Dim objBackUpLog As XmlDocument = New XmlDocument
Dim objNewParentNode As XmlElement
Dim objRootNode As XmlElement
Dim objLogEntryDateNode As XmlElement
Dim objNewChildNode As XmlElement
Dim objDateNodeList As XmlNodeList
Dim strStartTime As String
Dim strEndTime As String
Dim intFileSize As Integer = 0
Dim intLogEntryCount As Integer
Dim strBackUpLogPath As String =
"C:\SQLBackUp\SQLBackupLog.xml"
Dim objCurrentDateNode As XmlElement
Try
strStartTime = DateTime.Now.ToLongTimeString()

'-- delete old set of backups. GV 1/28/05
If UBound(objOldBackupFiles) > 0 Then
For x = 0 To UBound(objOldBackupFiles)
File.Delete(objOldBackupFiles(x).FullName)
Next
End If

'-- copy new set of backups. GV 1/28/05

'- if no backup files are found, throw an exception. GV
6/2/05
If intNewBackupFileCount < 1 Then
Throw New ApplicationException("No files were found.")

Else
For x = 0 To intNewBackupFileCount
objCurrentFile = objNewBackupFiles(x)
intFileSize = intFileSize + objCurrentFile.Length
objCurrentFile.CopyTo(strNewBackupPath & "\" &
objCurrentFile.Name)
Next
End If

strEndTime = DateTime.Now.ToLongTimeString()

'-- write file-copy info to XML log. GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)

' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)

' time started
objNewChildNode = objBackUpLog.CreateElement("starttime")
objNewChildNode.InnerText = strStartTime
objNewParentNode.AppendChild(objNewChildNode)

' time ended
objNewChildNode = objBackUpLog.CreateElement("endtime")
objNewChildNode.InnerText = strEndTime
objNewParentNode.AppendChild(objNewChildNode)

' total amount copied (in megs)
objNewChildNode = objBackUpLog.CreateElement("dataamount")
objNewChildNode.InnerText = CStr(Math.Round(intFileSize
/ 1048576, 2) & " Mb")
objNewParentNode.AppendChild(objNewChildNode)

' total number of files copied
objNewChildNode = objBackUpLog.CreateElement("nbroffiles")
objNewChildNode.InnerText = CStr(intNewBackupFileCount +
1)
objNewParentNode.AppendChild(objNewChildNode)

'-- delete entries older than 4 months. GV 1/31/05
objDateNodeList =
objBackUpLog.SelectNodes("/log/logentry/date")
For Each objCurrentDateNode In objDateNodeList
If DateValue(CDate(objCurrentDateNode.InnerXml)) <
DateValue(DateAdd("d", -120, DateTime.Now)) Then
objCurrentDateNode.RemoveAll()
objRootNode =
objCurrentDateNode.ParentNode.ParentNode

objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
End If
Next

'-- save changes. GV 1/31/05
objBackUpLog.Save(strBackUpLogPath)
intOperationSuccess = 1
Catch exc As Exception
'-- if exception occurs, write error info to XML log.
GV 1/28/05
objBackUpLog.Load(strBackUpLogPath)
objNewParentNode = objBackUpLog.CreateElement("logentry")
objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)

' current date
objNewChildNode = objBackUpLog.CreateElement("date")
objNewChildNode.InnerText =
DateTime.Now.ToShortDateString()
objNewParentNode.AppendChild(objNewChildNode)

' error header
objNewChildNode =
objBackUpLog.CreateElement("errorheader")
objNewChildNode.InnerText = "** ERROR **"
objNewParentNode.AppendChild(objNewChildNode)

' error description
objNewChildNode =
objBackUpLog.CreateElement("errordescription")
objNewChildNode.InnerText = exc.Message.ToString
objNewParentNode.AppendChild(objNewChildNode)
objBackUpLog.Save(strBackUpLogPath)
objEventLog.WriteEntry("**** ERROR **** " &
exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
intOperationSuccess = 0
'--
Finally
'-- destroy all objects. GV 1/28/05
x = Nothing
intFileSize = Nothing
intLogEntryCount = Nothing
If Not (objBackUpLog Is Nothing) Then objBackUpLog =
Nothing
If Not (objCurrentFile Is Nothing) Then objCurrentFile =
Nothing
intNewBackupFileCount = Nothing
If Not (objNewBackupFiles Is Nothing) Then
objNewBackupFiles = Nothing
If Not (objOldBackupFiles Is Nothing) Then
objOldBackupFiles = Nothing
If Not (objToDirectory Is Nothing) Then objToDirectory =
Nothing
If Not (strNewBackupPath Is Nothing) Then
strNewBackupPath = Nothing
If Not (objFromDirectory Is Nothing) Then
objFromDirectory = Nothing
If Not (strStartTime Is Nothing) Then strStartTime =
Nothing
If Not (strEndTime Is Nothing) Then strEndTime = Nothing
If Not (objRootNode Is Nothing) Then objRootNode = Nothing
If Not (objNewParentNode Is Nothing) Then
objNewParentNode = Nothing
If Not (objNewChildNode Is Nothing) Then objNewChildNode
= Nothing
If Not (objDateNodeList Is Nothing) Then objDateNodeList
= Nothing
If Not (objCurrentDateNode Is Nothing) Then
objCurrentDateNode = Nothing
If Not (objLogEntryDateNode Is Nothing) Then
objLogEntryDateNode = Nothing
If Not (strBackUpLogPath Is Nothing) Then
strBackUpLogPath = Nothing
'--
End TryAnother MVP has written a great article about this
http://west-wind.com/weblog/posts/1572.aspx

The crux is (and its a pain to get working) that using Anonymous
authentication (so no impersonation) the local ASPNET account has to have
the same credentials (username and password) on both machines in order to
delegate security. With basic authentication and impersonation you need to
use a domain account which can delegate and you can check how to mark your
impersonated account able to use security delegation here:
http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
This is also required if you want to use NTLM authentication over kerberos

Personally, I would implement a the remote server as an http device and use
http requests, checking the referrer whihc makes life a lot simpler than
using mapped network drives.
--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>I have an aspx page that is set up to copy backed-up DB files from a shared
> directory to a local folder. For some reason, it is being denied access to
> the network share. I have the web app running under a domain account that
> I
> know for a fact has access. it works fine when I log on to the network and
> browse the directory manually. Even when I grant full control to everyone
> on
> the share and the underlying folder itself, I still can't access it
> through
> code. The funny thing is though, this same code works fine when executed
> within a windows service which runs under the same domain account. Help!
> Code follows:
> **** this first line is the one throwing the exception ********
> Dim objFromDirectory As DirectoryInfo = New
> DirectoryInfo("\\[server]\[network share]
>
> Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> Dim objToDirectory As DirectoryInfo = New
> DirectoryInfo(strNewBackupPath)
> Dim objOldBackupFiles() As FileInfo =
> objToDirectory.GetFiles()
> Dim objNewBackupFiles() As FileInfo =
> objFromDirectory.GetFiles()
> Dim x As Integer
> Dim intNewBackupFileCount As Integer =
> UBound(objNewBackupFiles)
> Dim objCurrentFile As FileInfo
> Dim objBackUpLog As XmlDocument = New XmlDocument
> Dim objNewParentNode As XmlElement
> Dim objRootNode As XmlElement
> Dim objLogEntryDateNode As XmlElement
> Dim objNewChildNode As XmlElement
> Dim objDateNodeList As XmlNodeList
> Dim strStartTime As String
> Dim strEndTime As String
> Dim intFileSize As Integer = 0
> Dim intLogEntryCount As Integer
> Dim strBackUpLogPath As String =
> "C:\SQLBackUp\SQLBackupLog.xml"
> Dim objCurrentDateNode As XmlElement
> Try
> strStartTime = DateTime.Now.ToLongTimeString()
> '-- delete old set of backups. GV 1/28/05
> If UBound(objOldBackupFiles) > 0 Then
> For x = 0 To UBound(objOldBackupFiles)
> File.Delete(objOldBackupFiles(x).FullName)
> Next
> End If
> '-- copy new set of backups. GV 1/28/05
> '- if no backup files are found, throw an exception. GV
> 6/2/05
> If intNewBackupFileCount < 1 Then
> Throw New ApplicationException("No files were
> found.")
> Else
> For x = 0 To intNewBackupFileCount
> objCurrentFile = objNewBackupFiles(x)
> intFileSize = intFileSize +
> objCurrentFile.Length
> objCurrentFile.CopyTo(strNewBackupPath & "\" &
> objCurrentFile.Name)
> Next
> End If
> strEndTime = DateTime.Now.ToLongTimeString()
> '-- write file-copy info to XML log. GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' time started
> objNewChildNode =
> objBackUpLog.CreateElement("starttime")
> objNewChildNode.InnerText = strStartTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' time ended
> objNewChildNode = objBackUpLog.CreateElement("endtime")
> objNewChildNode.InnerText = strEndTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' total amount copied (in megs)
> objNewChildNode =
> objBackUpLog.CreateElement("dataamount")
> objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> / 1048576, 2) & " Mb")
> objNewParentNode.AppendChild(objNewChildNode)
> ' total number of files copied
> objNewChildNode =
> objBackUpLog.CreateElement("nbroffiles")
> objNewChildNode.InnerText = CStr(intNewBackupFileCount
> +
> 1)
> objNewParentNode.AppendChild(objNewChildNode)
> '-- delete entries older than 4 months. GV 1/31/05
> objDateNodeList =
> objBackUpLog.SelectNodes("/log/logentry/date")
> For Each objCurrentDateNode In objDateNodeList
> If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> DateValue(DateAdd("d", -120, DateTime.Now)) Then
> objCurrentDateNode.RemoveAll()
> objRootNode =
> objCurrentDateNode.ParentNode.ParentNode
> objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> End If
> Next
> '-- save changes. GV 1/31/05
> objBackUpLog.Save(strBackUpLogPath)
> intOperationSuccess = 1
> Catch exc As Exception
> '-- if exception occurs, write error info to XML log.
> GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' error header
> objNewChildNode =
> objBackUpLog.CreateElement("errorheader")
> objNewChildNode.InnerText = "** ERROR **"
> objNewParentNode.AppendChild(objNewChildNode)
> ' error description
> objNewChildNode =
> objBackUpLog.CreateElement("errordescription")
> objNewChildNode.InnerText = exc.Message.ToString
> objNewParentNode.AppendChild(objNewChildNode)
> objBackUpLog.Save(strBackUpLogPath)
> objEventLog.WriteEntry("**** ERROR **** " &
> exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> intOperationSuccess = 0
> '--
> Finally
> '-- destroy all objects. GV 1/28/05
> x = Nothing
> intFileSize = Nothing
> intLogEntryCount = Nothing
> If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> Nothing
> If Not (objCurrentFile Is Nothing) Then objCurrentFile
> =
> Nothing
> intNewBackupFileCount = Nothing
> If Not (objNewBackupFiles Is Nothing) Then
> objNewBackupFiles = Nothing
> If Not (objOldBackupFiles Is Nothing) Then
> objOldBackupFiles = Nothing
> If Not (objToDirectory Is Nothing) Then objToDirectory
> =
> Nothing
> If Not (strNewBackupPath Is Nothing) Then
> strNewBackupPath = Nothing
> If Not (objFromDirectory Is Nothing) Then
> objFromDirectory = Nothing
> If Not (strStartTime Is Nothing) Then strStartTime =
> Nothing
> If Not (strEndTime Is Nothing) Then strEndTime =
> Nothing
> If Not (objRootNode Is Nothing) Then objRootNode =
> Nothing
> If Not (objNewParentNode Is Nothing) Then
> objNewParentNode = Nothing
> If Not (objNewChildNode Is Nothing) Then
> objNewChildNode
> = Nothing
> If Not (objDateNodeList Is Nothing) Then
> objDateNodeList
> = Nothing
> If Not (objCurrentDateNode Is Nothing) Then
> objCurrentDateNode = Nothing
> If Not (objLogEntryDateNode Is Nothing) Then
> objLogEntryDateNode = Nothing
> If Not (strBackUpLogPath Is Nothing) Then
> strBackUpLogPath = Nothing
> '--
> End Try
Another MVP has written a great article about this
http://west-wind.com/weblog/posts/1572.aspx

The crux is (and its a pain to get working) that using Anonymous
authentication (so no impersonation) the local ASPNET account has to have
the same credentials (username and password) on both machines in order to
delegate security. With basic authentication and impersonation you need to
use a domain account which can delegate and you can check how to mark your
impersonated account able to use security delegation here:
http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
This is also required if you want to use NTLM authentication over kerberos

Personally, I would implement a the remote server as an http device and use
http requests, checking the referrer whihc makes life a lot simpler than
using mapped network drives.
--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>I have an aspx page that is set up to copy backed-up DB files from a shared
> directory to a local folder. For some reason, it is being denied access to
> the network share. I have the web app running under a domain account that
> I
> know for a fact has access. it works fine when I log on to the network and
> browse the directory manually. Even when I grant full control to everyone
> on
> the share and the underlying folder itself, I still can't access it
> through
> code. The funny thing is though, this same code works fine when executed
> within a windows service which runs under the same domain account. Help!
> Code follows:
> **** this first line is the one throwing the exception ********
> Dim objFromDirectory As DirectoryInfo = New
> DirectoryInfo("\\[server]\[network share]
>
> Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> Dim objToDirectory As DirectoryInfo = New
> DirectoryInfo(strNewBackupPath)
> Dim objOldBackupFiles() As FileInfo =
> objToDirectory.GetFiles()
> Dim objNewBackupFiles() As FileInfo =
> objFromDirectory.GetFiles()
> Dim x As Integer
> Dim intNewBackupFileCount As Integer =
> UBound(objNewBackupFiles)
> Dim objCurrentFile As FileInfo
> Dim objBackUpLog As XmlDocument = New XmlDocument
> Dim objNewParentNode As XmlElement
> Dim objRootNode As XmlElement
> Dim objLogEntryDateNode As XmlElement
> Dim objNewChildNode As XmlElement
> Dim objDateNodeList As XmlNodeList
> Dim strStartTime As String
> Dim strEndTime As String
> Dim intFileSize As Integer = 0
> Dim intLogEntryCount As Integer
> Dim strBackUpLogPath As String =
> "C:\SQLBackUp\SQLBackupLog.xml"
> Dim objCurrentDateNode As XmlElement
> Try
> strStartTime = DateTime.Now.ToLongTimeString()
> '-- delete old set of backups. GV 1/28/05
> If UBound(objOldBackupFiles) > 0 Then
> For x = 0 To UBound(objOldBackupFiles)
> File.Delete(objOldBackupFiles(x).FullName)
> Next
> End If
> '-- copy new set of backups. GV 1/28/05
> '- if no backup files are found, throw an exception. GV
> 6/2/05
> If intNewBackupFileCount < 1 Then
> Throw New ApplicationException("No files were
> found.")
> Else
> For x = 0 To intNewBackupFileCount
> objCurrentFile = objNewBackupFiles(x)
> intFileSize = intFileSize +
> objCurrentFile.Length
> objCurrentFile.CopyTo(strNewBackupPath & "\" &
> objCurrentFile.Name)
> Next
> End If
> strEndTime = DateTime.Now.ToLongTimeString()
> '-- write file-copy info to XML log. GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' time started
> objNewChildNode =
> objBackUpLog.CreateElement("starttime")
> objNewChildNode.InnerText = strStartTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' time ended
> objNewChildNode = objBackUpLog.CreateElement("endtime")
> objNewChildNode.InnerText = strEndTime
> objNewParentNode.AppendChild(objNewChildNode)
> ' total amount copied (in megs)
> objNewChildNode =
> objBackUpLog.CreateElement("dataamount")
> objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> / 1048576, 2) & " Mb")
> objNewParentNode.AppendChild(objNewChildNode)
> ' total number of files copied
> objNewChildNode =
> objBackUpLog.CreateElement("nbroffiles")
> objNewChildNode.InnerText = CStr(intNewBackupFileCount
> +
> 1)
> objNewParentNode.AppendChild(objNewChildNode)
> '-- delete entries older than 4 months. GV 1/31/05
> objDateNodeList =
> objBackUpLog.SelectNodes("/log/logentry/date")
> For Each objCurrentDateNode In objDateNodeList
> If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> DateValue(DateAdd("d", -120, DateTime.Now)) Then
> objCurrentDateNode.RemoveAll()
> objRootNode =
> objCurrentDateNode.ParentNode.ParentNode
> objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> End If
> Next
> '-- save changes. GV 1/31/05
> objBackUpLog.Save(strBackUpLogPath)
> intOperationSuccess = 1
> Catch exc As Exception
> '-- if exception occurs, write error info to XML log.
> GV 1/28/05
> objBackUpLog.Load(strBackUpLogPath)
> objNewParentNode =
> objBackUpLog.CreateElement("logentry")
> objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> ' current date
> objNewChildNode = objBackUpLog.CreateElement("date")
> objNewChildNode.InnerText =
> DateTime.Now.ToShortDateString()
> objNewParentNode.AppendChild(objNewChildNode)
> ' error header
> objNewChildNode =
> objBackUpLog.CreateElement("errorheader")
> objNewChildNode.InnerText = "** ERROR **"
> objNewParentNode.AppendChild(objNewChildNode)
> ' error description
> objNewChildNode =
> objBackUpLog.CreateElement("errordescription")
> objNewChildNode.InnerText = exc.Message.ToString
> objNewParentNode.AppendChild(objNewChildNode)
> objBackUpLog.Save(strBackUpLogPath)
> objEventLog.WriteEntry("**** ERROR **** " &
> exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> intOperationSuccess = 0
> '--
> Finally
> '-- destroy all objects. GV 1/28/05
> x = Nothing
> intFileSize = Nothing
> intLogEntryCount = Nothing
> If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> Nothing
> If Not (objCurrentFile Is Nothing) Then objCurrentFile
> =
> Nothing
> intNewBackupFileCount = Nothing
> If Not (objNewBackupFiles Is Nothing) Then
> objNewBackupFiles = Nothing
> If Not (objOldBackupFiles Is Nothing) Then
> objOldBackupFiles = Nothing
> If Not (objToDirectory Is Nothing) Then objToDirectory
> =
> Nothing
> If Not (strNewBackupPath Is Nothing) Then
> strNewBackupPath = Nothing
> If Not (objFromDirectory Is Nothing) Then
> objFromDirectory = Nothing
> If Not (strStartTime Is Nothing) Then strStartTime =
> Nothing
> If Not (strEndTime Is Nothing) Then strEndTime =
> Nothing
> If Not (objRootNode Is Nothing) Then objRootNode =
> Nothing
> If Not (objNewParentNode Is Nothing) Then
> objNewParentNode = Nothing
> If Not (objNewChildNode Is Nothing) Then
> objNewChildNode
> = Nothing
> If Not (objDateNodeList Is Nothing) Then
> objDateNodeList
> = Nothing
> If Not (objCurrentDateNode Is Nothing) Then
> objCurrentDateNode = Nothing
> If Not (objLogEntryDateNode Is Nothing) Then
> objLogEntryDateNode = Nothing
> If Not (strBackUpLogPath Is Nothing) Then
> strBackUpLogPath = Nothing
> '--
> End Try
Problem solved! All I had to do was set "identity impersonate" to "true" in
my web.config. Thank you so much!

"John Timney (ASP.NET MVP)" wrote:

> Another MVP has written a great article about this
> http://west-wind.com/weblog/posts/1572.aspx
> The crux is (and its a pain to get working) that using Anonymous
> authentication (so no impersonation) the local ASPNET account has to have
> the same credentials (username and password) on both machines in order to
> delegate security. With basic authentication and impersonation you need to
> use a domain account which can delegate and you can check how to mark your
> impersonated account able to use security delegation here:
> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
> This is also required if you want to use NTLM authentication over kerberos
> Personally, I would implement a the remote server as an http device and use
> http requests, checking the referrer whihc makes life a lot simpler than
> using mapped network drives.
> --
> Regards
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
> >I have an aspx page that is set up to copy backed-up DB files from a shared
> > directory to a local folder. For some reason, it is being denied access to
> > the network share. I have the web app running under a domain account that
> > I
> > know for a fact has access. it works fine when I log on to the network and
> > browse the directory manually. Even when I grant full control to everyone
> > on
> > the share and the underlying folder itself, I still can't access it
> > through
> > code. The funny thing is though, this same code works fine when executed
> > within a windows service which runs under the same domain account. Help!
> > Code follows:
> > **** this first line is the one throwing the exception ********
> > Dim objFromDirectory As DirectoryInfo = New
> > DirectoryInfo("\\[server]\[network share]
> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> > Dim objToDirectory As DirectoryInfo = New
> > DirectoryInfo(strNewBackupPath)
> > Dim objOldBackupFiles() As FileInfo =
> > objToDirectory.GetFiles()
> > Dim objNewBackupFiles() As FileInfo =
> > objFromDirectory.GetFiles()
> > Dim x As Integer
> > Dim intNewBackupFileCount As Integer =
> > UBound(objNewBackupFiles)
> > Dim objCurrentFile As FileInfo
> > Dim objBackUpLog As XmlDocument = New XmlDocument
> > Dim objNewParentNode As XmlElement
> > Dim objRootNode As XmlElement
> > Dim objLogEntryDateNode As XmlElement
> > Dim objNewChildNode As XmlElement
> > Dim objDateNodeList As XmlNodeList
> > Dim strStartTime As String
> > Dim strEndTime As String
> > Dim intFileSize As Integer = 0
> > Dim intLogEntryCount As Integer
> > Dim strBackUpLogPath As String =
> > "C:\SQLBackUp\SQLBackupLog.xml"
> > Dim objCurrentDateNode As XmlElement
> > Try
> > strStartTime = DateTime.Now.ToLongTimeString()
> > '-- delete old set of backups. GV 1/28/05
> > If UBound(objOldBackupFiles) > 0 Then
> > For x = 0 To UBound(objOldBackupFiles)
> > File.Delete(objOldBackupFiles(x).FullName)
> > Next
> > End If
> > '-- copy new set of backups. GV 1/28/05
> > '- if no backup files are found, throw an exception. GV
> > 6/2/05
> > If intNewBackupFileCount < 1 Then
> > Throw New ApplicationException("No files were
> > found.")
> > Else
> > For x = 0 To intNewBackupFileCount
> > objCurrentFile = objNewBackupFiles(x)
> > intFileSize = intFileSize +
> > objCurrentFile.Length
> > objCurrentFile.CopyTo(strNewBackupPath & "\" &
> > objCurrentFile.Name)
> > Next
> > End If
> > strEndTime = DateTime.Now.ToLongTimeString()
> > '-- write file-copy info to XML log. GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time started
> > objNewChildNode =
> > objBackUpLog.CreateElement("starttime")
> > objNewChildNode.InnerText = strStartTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time ended
> > objNewChildNode = objBackUpLog.CreateElement("endtime")
> > objNewChildNode.InnerText = strEndTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total amount copied (in megs)
> > objNewChildNode =
> > objBackUpLog.CreateElement("dataamount")
> > objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> > / 1048576, 2) & " Mb")
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total number of files copied
> > objNewChildNode =
> > objBackUpLog.CreateElement("nbroffiles")
> > objNewChildNode.InnerText = CStr(intNewBackupFileCount
> > +
> > 1)
> > objNewParentNode.AppendChild(objNewChildNode)
> > '-- delete entries older than 4 months. GV 1/31/05
> > objDateNodeList =
> > objBackUpLog.SelectNodes("/log/logentry/date")
> > For Each objCurrentDateNode In objDateNodeList
> > If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
> > objCurrentDateNode.RemoveAll()
> > objRootNode =
> > objCurrentDateNode.ParentNode.ParentNode
> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> > End If
> > Next
> > '-- save changes. GV 1/31/05
> > objBackUpLog.Save(strBackUpLogPath)
> > intOperationSuccess = 1
> > Catch exc As Exception
> > '-- if exception occurs, write error info to XML log.
> > GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error header
> > objNewChildNode =
> > objBackUpLog.CreateElement("errorheader")
> > objNewChildNode.InnerText = "** ERROR **"
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error description
> > objNewChildNode =
> > objBackUpLog.CreateElement("errordescription")
> > objNewChildNode.InnerText = exc.Message.ToString
> > objNewParentNode.AppendChild(objNewChildNode)
> > objBackUpLog.Save(strBackUpLogPath)
> > objEventLog.WriteEntry("**** ERROR **** " &
> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> > intOperationSuccess = 0
> > '--
> > Finally
> > '-- destroy all objects. GV 1/28/05
> > x = Nothing
> > intFileSize = Nothing
> > intLogEntryCount = Nothing
> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> > Nothing
> > If Not (objCurrentFile Is Nothing) Then objCurrentFile
> > =
> > Nothing
> > intNewBackupFileCount = Nothing
> > If Not (objNewBackupFiles Is Nothing) Then
> > objNewBackupFiles = Nothing
> > If Not (objOldBackupFiles Is Nothing) Then
> > objOldBackupFiles = Nothing
> > If Not (objToDirectory Is Nothing) Then objToDirectory
> > =
> > Nothing
> > If Not (strNewBackupPath Is Nothing) Then
> > strNewBackupPath = Nothing
> > If Not (objFromDirectory Is Nothing) Then
> > objFromDirectory = Nothing
> > If Not (strStartTime Is Nothing) Then strStartTime =
> > Nothing
> > If Not (strEndTime Is Nothing) Then strEndTime =
> > Nothing
> > If Not (objRootNode Is Nothing) Then objRootNode =
> > Nothing
> > If Not (objNewParentNode Is Nothing) Then
> > objNewParentNode = Nothing
> > If Not (objNewChildNode Is Nothing) Then
> > objNewChildNode
> > = Nothing
> > If Not (objDateNodeList Is Nothing) Then
> > objDateNodeList
> > = Nothing
> > If Not (objCurrentDateNode Is Nothing) Then
> > objCurrentDateNode = Nothing
> > If Not (objLogEntryDateNode Is Nothing) Then
> > objLogEntryDateNode = Nothing
> > If Not (strBackUpLogPath Is Nothing) Then
> > strBackUpLogPath = Nothing
> > '--
> > End Try
>
glad your sorted :)

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:CCC31167-8012-4FC7-9EC7-3F125F515339@.microsoft.com...
> Problem solved! All I had to do was set "identity impersonate" to "true"
> in
> my web.config. Thank you so much!
> "John Timney (ASP.NET MVP)" wrote:
>> Another MVP has written a great article about this
>> http://west-wind.com/weblog/posts/1572.aspx
>>
>> The crux is (and its a pain to get working) that using Anonymous
>> authentication (so no impersonation) the local ASPNET account has to have
>> the same credentials (username and password) on both machines in order to
>> delegate security. With basic authentication and impersonation you need
>> to
>> use a domain account which can delegate and you can check how to mark
>> your
>> impersonated account able to use security delegation here:
>> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
>> This is also required if you want to use NTLM authentication over
>> kerberos
>>
>> Personally, I would implement a the remote server as an http device and
>> use
>> http requests, checking the referrer whihc makes life a lot simpler than
>> using mapped network drives.
>> --
>> Regards
>>
>> John Timney
>> ASP.NET MVP
>> Microsoft Regional Director
>>
>> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
>> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>> >I have an aspx page that is set up to copy backed-up DB files from a
>> >shared
>> > directory to a local folder. For some reason, it is being denied access
>> > to
>> > the network share. I have the web app running under a domain account
>> > that
>> > I
>> > know for a fact has access. it works fine when I log on to the network
>> > and
>> > browse the directory manually. Even when I grant full control to
>> > everyone
>> > on
>> > the share and the underlying folder itself, I still can't access it
>> > through
>> > code. The funny thing is though, this same code works fine when
>> > executed
>> > within a windows service which runs under the same domain account.
>> > Help!
>>> > Code follows:
>>> > **** this first line is the one throwing the exception ********
>> > Dim objFromDirectory As DirectoryInfo = New
>> > DirectoryInfo("\\[server]\[network share]
>>>> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
>> > Dim objToDirectory As DirectoryInfo = New
>> > DirectoryInfo(strNewBackupPath)
>> > Dim objOldBackupFiles() As FileInfo =
>> > objToDirectory.GetFiles()
>> > Dim objNewBackupFiles() As FileInfo =
>> > objFromDirectory.GetFiles()
>> > Dim x As Integer
>> > Dim intNewBackupFileCount As Integer =
>> > UBound(objNewBackupFiles)
>> > Dim objCurrentFile As FileInfo
>> > Dim objBackUpLog As XmlDocument = New XmlDocument
>> > Dim objNewParentNode As XmlElement
>> > Dim objRootNode As XmlElement
>> > Dim objLogEntryDateNode As XmlElement
>> > Dim objNewChildNode As XmlElement
>> > Dim objDateNodeList As XmlNodeList
>> > Dim strStartTime As String
>> > Dim strEndTime As String
>> > Dim intFileSize As Integer = 0
>> > Dim intLogEntryCount As Integer
>> > Dim strBackUpLogPath As String =
>> > "C:\SQLBackUp\SQLBackupLog.xml"
>> > Dim objCurrentDateNode As XmlElement
>> > Try
>> > strStartTime = DateTime.Now.ToLongTimeString()
>>> > '-- delete old set of backups. GV 1/28/05
>> > If UBound(objOldBackupFiles) > 0 Then
>> > For x = 0 To UBound(objOldBackupFiles)
>> > File.Delete(objOldBackupFiles(x).FullName)
>> > Next
>> > End If
>>> > '-- copy new set of backups. GV 1/28/05
>>> > '- if no backup files are found, throw an exception.
>> > GV
>> > 6/2/05
>> > If intNewBackupFileCount < 1 Then
>> > Throw New ApplicationException("No files were
>> > found.")
>>> > Else
>> > For x = 0 To intNewBackupFileCount
>> > objCurrentFile = objNewBackupFiles(x)
>> > intFileSize = intFileSize +
>> > objCurrentFile.Length
>> > objCurrentFile.CopyTo(strNewBackupPath & "\"
>> > &
>> > objCurrentFile.Name)
>> > Next
>> > End If
>>> > strEndTime = DateTime.Now.ToLongTimeString()
>>> > '-- write file-copy info to XML log. GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time started
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("starttime")
>> > objNewChildNode.InnerText = strStartTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time ended
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("endtime")
>> > objNewChildNode.InnerText = strEndTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total amount copied (in megs)
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("dataamount")
>> > objNewChildNode.InnerText =
>> > CStr(Math.Round(intFileSize
>> > / 1048576, 2) & " Mb")
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total number of files copied
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("nbroffiles")
>> > objNewChildNode.InnerText =
>> > CStr(intNewBackupFileCount
>> > +
>> > 1)
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > '-- delete entries older than 4 months. GV 1/31/05
>> > objDateNodeList =
>> > objBackUpLog.SelectNodes("/log/logentry/date")
>> > For Each objCurrentDateNode In objDateNodeList
>> > If DateValue(CDate(objCurrentDateNode.InnerXml))
>> > <
>> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
>> > objCurrentDateNode.RemoveAll()
>> > objRootNode =
>> > objCurrentDateNode.ParentNode.ParentNode
>>> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
>> > End If
>> > Next
>>> > '-- save changes. GV 1/31/05
>> > objBackUpLog.Save(strBackUpLogPath)
>> > intOperationSuccess = 1
>> > Catch exc As Exception
>> > '-- if exception occurs, write error info to XML
>> > log.
>> > GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error header
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errorheader")
>> > objNewChildNode.InnerText = "** ERROR **"
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error description
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errordescription")
>> > objNewChildNode.InnerText = exc.Message.ToString
>> > objNewParentNode.AppendChild(objNewChildNode)
>> > objBackUpLog.Save(strBackUpLogPath)
>> > objEventLog.WriteEntry("**** ERROR **** " &
>> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
>> > intOperationSuccess = 0
>> > '--
>> > Finally
>> > '-- destroy all objects. GV 1/28/05
>> > x = Nothing
>> > intFileSize = Nothing
>> > intLogEntryCount = Nothing
>> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
>> > Nothing
>> > If Not (objCurrentFile Is Nothing) Then
>> > objCurrentFile
>> > =
>> > Nothing
>> > intNewBackupFileCount = Nothing
>> > If Not (objNewBackupFiles Is Nothing) Then
>> > objNewBackupFiles = Nothing
>> > If Not (objOldBackupFiles Is Nothing) Then
>> > objOldBackupFiles = Nothing
>> > If Not (objToDirectory Is Nothing) Then
>> > objToDirectory
>> > =
>> > Nothing
>> > If Not (strNewBackupPath Is Nothing) Then
>> > strNewBackupPath = Nothing
>> > If Not (objFromDirectory Is Nothing) Then
>> > objFromDirectory = Nothing
>> > If Not (strStartTime Is Nothing) Then strStartTime =
>> > Nothing
>> > If Not (strEndTime Is Nothing) Then strEndTime =
>> > Nothing
>> > If Not (objRootNode Is Nothing) Then objRootNode =
>> > Nothing
>> > If Not (objNewParentNode Is Nothing) Then
>> > objNewParentNode = Nothing
>> > If Not (objNewChildNode Is Nothing) Then
>> > objNewChildNode
>> > = Nothing
>> > If Not (objDateNodeList Is Nothing) Then
>> > objDateNodeList
>> > = Nothing
>> > If Not (objCurrentDateNode Is Nothing) Then
>> > objCurrentDateNode = Nothing
>> > If Not (objLogEntryDateNode Is Nothing) Then
>> > objLogEntryDateNode = Nothing
>> > If Not (strBackUpLogPath Is Nothing) Then
>> > strBackUpLogPath = Nothing
>> > '--
>> > End Try
>>>
>>
>
Problem solved! All I had to do was set "identity impersonate" to "true" in
my web.config. Thank you so much!

"John Timney (ASP.NET MVP)" wrote:

> Another MVP has written a great article about this
> http://west-wind.com/weblog/posts/1572.aspx
> The crux is (and its a pain to get working) that using Anonymous
> authentication (so no impersonation) the local ASPNET account has to have
> the same credentials (username and password) on both machines in order to
> delegate security. With basic authentication and impersonation you need to
> use a domain account which can delegate and you can check how to mark your
> impersonated account able to use security delegation here:
> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
> This is also required if you want to use NTLM authentication over kerberos
> Personally, I would implement a the remote server as an http device and use
> http requests, checking the referrer whihc makes life a lot simpler than
> using mapped network drives.
> --
> Regards
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
> >I have an aspx page that is set up to copy backed-up DB files from a shared
> > directory to a local folder. For some reason, it is being denied access to
> > the network share. I have the web app running under a domain account that
> > I
> > know for a fact has access. it works fine when I log on to the network and
> > browse the directory manually. Even when I grant full control to everyone
> > on
> > the share and the underlying folder itself, I still can't access it
> > through
> > code. The funny thing is though, this same code works fine when executed
> > within a windows service which runs under the same domain account. Help!
> > Code follows:
> > **** this first line is the one throwing the exception ********
> > Dim objFromDirectory As DirectoryInfo = New
> > DirectoryInfo("\\[server]\[network share]
> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
> > Dim objToDirectory As DirectoryInfo = New
> > DirectoryInfo(strNewBackupPath)
> > Dim objOldBackupFiles() As FileInfo =
> > objToDirectory.GetFiles()
> > Dim objNewBackupFiles() As FileInfo =
> > objFromDirectory.GetFiles()
> > Dim x As Integer
> > Dim intNewBackupFileCount As Integer =
> > UBound(objNewBackupFiles)
> > Dim objCurrentFile As FileInfo
> > Dim objBackUpLog As XmlDocument = New XmlDocument
> > Dim objNewParentNode As XmlElement
> > Dim objRootNode As XmlElement
> > Dim objLogEntryDateNode As XmlElement
> > Dim objNewChildNode As XmlElement
> > Dim objDateNodeList As XmlNodeList
> > Dim strStartTime As String
> > Dim strEndTime As String
> > Dim intFileSize As Integer = 0
> > Dim intLogEntryCount As Integer
> > Dim strBackUpLogPath As String =
> > "C:\SQLBackUp\SQLBackupLog.xml"
> > Dim objCurrentDateNode As XmlElement
> > Try
> > strStartTime = DateTime.Now.ToLongTimeString()
> > '-- delete old set of backups. GV 1/28/05
> > If UBound(objOldBackupFiles) > 0 Then
> > For x = 0 To UBound(objOldBackupFiles)
> > File.Delete(objOldBackupFiles(x).FullName)
> > Next
> > End If
> > '-- copy new set of backups. GV 1/28/05
> > '- if no backup files are found, throw an exception. GV
> > 6/2/05
> > If intNewBackupFileCount < 1 Then
> > Throw New ApplicationException("No files were
> > found.")
> > Else
> > For x = 0 To intNewBackupFileCount
> > objCurrentFile = objNewBackupFiles(x)
> > intFileSize = intFileSize +
> > objCurrentFile.Length
> > objCurrentFile.CopyTo(strNewBackupPath & "\" &
> > objCurrentFile.Name)
> > Next
> > End If
> > strEndTime = DateTime.Now.ToLongTimeString()
> > '-- write file-copy info to XML log. GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time started
> > objNewChildNode =
> > objBackUpLog.CreateElement("starttime")
> > objNewChildNode.InnerText = strStartTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' time ended
> > objNewChildNode = objBackUpLog.CreateElement("endtime")
> > objNewChildNode.InnerText = strEndTime
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total amount copied (in megs)
> > objNewChildNode =
> > objBackUpLog.CreateElement("dataamount")
> > objNewChildNode.InnerText = CStr(Math.Round(intFileSize
> > / 1048576, 2) & " Mb")
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' total number of files copied
> > objNewChildNode =
> > objBackUpLog.CreateElement("nbroffiles")
> > objNewChildNode.InnerText = CStr(intNewBackupFileCount
> > +
> > 1)
> > objNewParentNode.AppendChild(objNewChildNode)
> > '-- delete entries older than 4 months. GV 1/31/05
> > objDateNodeList =
> > objBackUpLog.SelectNodes("/log/logentry/date")
> > For Each objCurrentDateNode In objDateNodeList
> > If DateValue(CDate(objCurrentDateNode.InnerXml)) <
> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
> > objCurrentDateNode.RemoveAll()
> > objRootNode =
> > objCurrentDateNode.ParentNode.ParentNode
> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
> > End If
> > Next
> > '-- save changes. GV 1/31/05
> > objBackUpLog.Save(strBackUpLogPath)
> > intOperationSuccess = 1
> > Catch exc As Exception
> > '-- if exception occurs, write error info to XML log.
> > GV 1/28/05
> > objBackUpLog.Load(strBackUpLogPath)
> > objNewParentNode =
> > objBackUpLog.CreateElement("logentry")
> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
> > ' current date
> > objNewChildNode = objBackUpLog.CreateElement("date")
> > objNewChildNode.InnerText =
> > DateTime.Now.ToShortDateString()
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error header
> > objNewChildNode =
> > objBackUpLog.CreateElement("errorheader")
> > objNewChildNode.InnerText = "** ERROR **"
> > objNewParentNode.AppendChild(objNewChildNode)
> > ' error description
> > objNewChildNode =
> > objBackUpLog.CreateElement("errordescription")
> > objNewChildNode.InnerText = exc.Message.ToString
> > objNewParentNode.AppendChild(objNewChildNode)
> > objBackUpLog.Save(strBackUpLogPath)
> > objEventLog.WriteEntry("**** ERROR **** " &
> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
> > intOperationSuccess = 0
> > '--
> > Finally
> > '-- destroy all objects. GV 1/28/05
> > x = Nothing
> > intFileSize = Nothing
> > intLogEntryCount = Nothing
> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
> > Nothing
> > If Not (objCurrentFile Is Nothing) Then objCurrentFile
> > =
> > Nothing
> > intNewBackupFileCount = Nothing
> > If Not (objNewBackupFiles Is Nothing) Then
> > objNewBackupFiles = Nothing
> > If Not (objOldBackupFiles Is Nothing) Then
> > objOldBackupFiles = Nothing
> > If Not (objToDirectory Is Nothing) Then objToDirectory
> > =
> > Nothing
> > If Not (strNewBackupPath Is Nothing) Then
> > strNewBackupPath = Nothing
> > If Not (objFromDirectory Is Nothing) Then
> > objFromDirectory = Nothing
> > If Not (strStartTime Is Nothing) Then strStartTime =
> > Nothing
> > If Not (strEndTime Is Nothing) Then strEndTime =
> > Nothing
> > If Not (objRootNode Is Nothing) Then objRootNode =
> > Nothing
> > If Not (objNewParentNode Is Nothing) Then
> > objNewParentNode = Nothing
> > If Not (objNewChildNode Is Nothing) Then
> > objNewChildNode
> > = Nothing
> > If Not (objDateNodeList Is Nothing) Then
> > objDateNodeList
> > = Nothing
> > If Not (objCurrentDateNode Is Nothing) Then
> > objCurrentDateNode = Nothing
> > If Not (objLogEntryDateNode Is Nothing) Then
> > objLogEntryDateNode = Nothing
> > If Not (strBackUpLogPath Is Nothing) Then
> > strBackUpLogPath = Nothing
> > '--
> > End Try
>
glad your sorted :)

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
news:CCC31167-8012-4FC7-9EC7-3F125F515339@.microsoft.com...
> Problem solved! All I had to do was set "identity impersonate" to "true"
> in
> my web.config. Thank you so much!
> "John Timney (ASP.NET MVP)" wrote:
>> Another MVP has written a great article about this
>> http://west-wind.com/weblog/posts/1572.aspx
>>
>> The crux is (and its a pain to get working) that using Anonymous
>> authentication (so no impersonation) the local ASPNET account has to have
>> the same credentials (username and password) on both machines in order to
>> delegate security. With basic authentication and impersonation you need
>> to
>> use a domain account which can delegate and you can check how to mark
>> your
>> impersonated account able to use security delegation here:
>> http://msdn.microsoft.com/library/d.../SecNetHT05.asp.
>> This is also required if you want to use NTLM authentication over
>> kerberos
>>
>> Personally, I would implement a the remote server as an http device and
>> use
>> http requests, checking the referrer whihc makes life a lot simpler than
>> using mapped network drives.
>> --
>> Regards
>>
>> John Timney
>> ASP.NET MVP
>> Microsoft Regional Director
>>
>> "Glenn Venzke" <GlennVenzke@.discussions.microsoft.com> wrote in message
>> news:9B4BC708-162A-4C50-8AF1-85D829D5E579@.microsoft.com...
>> >I have an aspx page that is set up to copy backed-up DB files from a
>> >shared
>> > directory to a local folder. For some reason, it is being denied access
>> > to
>> > the network share. I have the web app running under a domain account
>> > that
>> > I
>> > know for a fact has access. it works fine when I log on to the network
>> > and
>> > browse the directory manually. Even when I grant full control to
>> > everyone
>> > on
>> > the share and the underlying folder itself, I still can't access it
>> > through
>> > code. The funny thing is though, this same code works fine when
>> > executed
>> > within a windows service which runs under the same domain account.
>> > Help!
>>> > Code follows:
>>> > **** this first line is the one throwing the exception ********
>> > Dim objFromDirectory As DirectoryInfo = New
>> > DirectoryInfo("\\[server]\[network share]
>>>> > Dim strNewBackupPath As String = "C:\SQLBackUp\Data"
>> > Dim objToDirectory As DirectoryInfo = New
>> > DirectoryInfo(strNewBackupPath)
>> > Dim objOldBackupFiles() As FileInfo =
>> > objToDirectory.GetFiles()
>> > Dim objNewBackupFiles() As FileInfo =
>> > objFromDirectory.GetFiles()
>> > Dim x As Integer
>> > Dim intNewBackupFileCount As Integer =
>> > UBound(objNewBackupFiles)
>> > Dim objCurrentFile As FileInfo
>> > Dim objBackUpLog As XmlDocument = New XmlDocument
>> > Dim objNewParentNode As XmlElement
>> > Dim objRootNode As XmlElement
>> > Dim objLogEntryDateNode As XmlElement
>> > Dim objNewChildNode As XmlElement
>> > Dim objDateNodeList As XmlNodeList
>> > Dim strStartTime As String
>> > Dim strEndTime As String
>> > Dim intFileSize As Integer = 0
>> > Dim intLogEntryCount As Integer
>> > Dim strBackUpLogPath As String =
>> > "C:\SQLBackUp\SQLBackupLog.xml"
>> > Dim objCurrentDateNode As XmlElement
>> > Try
>> > strStartTime = DateTime.Now.ToLongTimeString()
>>> > '-- delete old set of backups. GV 1/28/05
>> > If UBound(objOldBackupFiles) > 0 Then
>> > For x = 0 To UBound(objOldBackupFiles)
>> > File.Delete(objOldBackupFiles(x).FullName)
>> > Next
>> > End If
>>> > '-- copy new set of backups. GV 1/28/05
>>> > '- if no backup files are found, throw an exception.
>> > GV
>> > 6/2/05
>> > If intNewBackupFileCount < 1 Then
>> > Throw New ApplicationException("No files were
>> > found.")
>>> > Else
>> > For x = 0 To intNewBackupFileCount
>> > objCurrentFile = objNewBackupFiles(x)
>> > intFileSize = intFileSize +
>> > objCurrentFile.Length
>> > objCurrentFile.CopyTo(strNewBackupPath & "\"
>> > &
>> > objCurrentFile.Name)
>> > Next
>> > End If
>>> > strEndTime = DateTime.Now.ToLongTimeString()
>>> > '-- write file-copy info to XML log. GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time started
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("starttime")
>> > objNewChildNode.InnerText = strStartTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' time ended
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("endtime")
>> > objNewChildNode.InnerText = strEndTime
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total amount copied (in megs)
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("dataamount")
>> > objNewChildNode.InnerText =
>> > CStr(Math.Round(intFileSize
>> > / 1048576, 2) & " Mb")
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' total number of files copied
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("nbroffiles")
>> > objNewChildNode.InnerText =
>> > CStr(intNewBackupFileCount
>> > +
>> > 1)
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > '-- delete entries older than 4 months. GV 1/31/05
>> > objDateNodeList =
>> > objBackUpLog.SelectNodes("/log/logentry/date")
>> > For Each objCurrentDateNode In objDateNodeList
>> > If DateValue(CDate(objCurrentDateNode.InnerXml))
>> > <
>> > DateValue(DateAdd("d", -120, DateTime.Now)) Then
>> > objCurrentDateNode.RemoveAll()
>> > objRootNode =
>> > objCurrentDateNode.ParentNode.ParentNode
>>> > objRootNode.RemoveChild(objCurrentDateNode.ParentN ode)
>> > End If
>> > Next
>>> > '-- save changes. GV 1/31/05
>> > objBackUpLog.Save(strBackUpLogPath)
>> > intOperationSuccess = 1
>> > Catch exc As Exception
>> > '-- if exception occurs, write error info to XML
>> > log.
>> > GV 1/28/05
>> > objBackUpLog.Load(strBackUpLogPath)
>> > objNewParentNode =
>> > objBackUpLog.CreateElement("logentry")
>>> > objBackUpLog.DocumentElement.AppendChild(objNewPar entNode)
>>> > ' current date
>> > objNewChildNode = objBackUpLog.CreateElement("date")
>> > objNewChildNode.InnerText =
>> > DateTime.Now.ToShortDateString()
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error header
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errorheader")
>> > objNewChildNode.InnerText = "** ERROR **"
>> > objNewParentNode.AppendChild(objNewChildNode)
>>> > ' error description
>> > objNewChildNode =
>> > objBackUpLog.CreateElement("errordescription")
>> > objNewChildNode.InnerText = exc.Message.ToString
>> > objNewParentNode.AppendChild(objNewChildNode)
>> > objBackUpLog.Save(strBackUpLogPath)
>> > objEventLog.WriteEntry("**** ERROR **** " &
>> > exc.Message.ToString() & " occurred on " & DateTime.Now & ".")
>> > intOperationSuccess = 0
>> > '--
>> > Finally
>> > '-- destroy all objects. GV 1/28/05
>> > x = Nothing
>> > intFileSize = Nothing
>> > intLogEntryCount = Nothing
>> > If Not (objBackUpLog Is Nothing) Then objBackUpLog =
>> > Nothing
>> > If Not (objCurrentFile Is Nothing) Then
>> > objCurrentFile
>> > =
>> > Nothing
>> > intNewBackupFileCount = Nothing
>> > If Not (objNewBackupFiles Is Nothing) Then
>> > objNewBackupFiles = Nothing
>> > If Not (objOldBackupFiles Is Nothing) Then
>> > objOldBackupFiles = Nothing
>> > If Not (objToDirectory Is Nothing) Then
>> > objToDirectory
>> > =
>> > Nothing
>> > If Not (strNewBackupPath Is Nothing) Then
>> > strNewBackupPath = Nothing
>> > If Not (objFromDirectory Is Nothing) Then
>> > objFromDirectory = Nothing
>> > If Not (strStartTime Is Nothing) Then strStartTime =
>> > Nothing
>> > If Not (strEndTime Is Nothing) Then strEndTime =
>> > Nothing
>> > If Not (objRootNode Is Nothing) Then objRootNode =
>> > Nothing
>> > If Not (objNewParentNode Is Nothing) Then
>> > objNewParentNode = Nothing
>> > If Not (objNewChildNode Is Nothing) Then
>> > objNewChildNode
>> > = Nothing
>> > If Not (objDateNodeList Is Nothing) Then
>> > objDateNodeList
>> > = Nothing
>> > If Not (objCurrentDateNode Is Nothing) Then
>> > objCurrentDateNode = Nothing
>> > If Not (objLogEntryDateNode Is Nothing) Then
>> > objLogEntryDateNode = Nothing
>> > If Not (strBackUpLogPath Is Nothing) Then
>> > strBackUpLogPath = Nothing
>> > '--
>> > End Try
>>>
>>
>

System.IO.File.Copy not copying and no error

I'd suggest wrapping the copy in a Try/Catch block just to be sure. Then
throw a new exception, outputing your source/destination paths along with
the original exception:

Try
System.IO.File.Copy(Source,Dest)
Catch ex as exception
throw new Exception("Source: '" & source & "' - Dest: '" & dest &
"'",ex)
end try

also, put a break point at the Throw, and examine your variables.

"Xander Q." <xander_q@dotnet.itags.org.hotmail.com> wrote in message
news:1958ff15.0307052341.260d3083@dotnet.itags.org.posting.google.c om...
> Something really strange is happening. i'm using the following code to
> copy a file. this worked on my development machine, but when i moved
> it to the server (win2k) it is not copying the file and not generating
> an error. it just merrily goes on.
> ---------------------
> source= Server.MapPath("/TTClaimsForm2/Reports/xxx.doc")
> dest= Server.MapPath("/TTClaimsForm2/Reports/Temp/xxx.doc")
> System.IO.File.Copy(source, dest)
> ---------------------
>
> i checked the value of dest and it's correct. i replaced it with an
> empty string and it gave an error as expected.
> BUT i noticed that if i hard code destination like this:
> System.IO.File.Copy(source,
> "C:\inetpub\wwwroot\ttclaimsform2\Temp\xxx.doc") then the copy works.
> how can this be happening?"David Waz..." <dlw@.pickpro.com> wrote in message news:<bhZNa.1682$Ro2.1449@.newssvr31.news.prodigy.com>...
> I'd suggest wrapping the copy in a Try/Catch block just to be sure. Then
> throw a new exception, outputing your source/destination paths along with
> the original exception:

ah yes i neglected to mention that i already did that, and the value
of 'dest' is correct. it is the same as the hard-coded string and yet
it fails...

damn i hate this stuff!!!

but thx for the input...

System.IO.File class and IP paths?

I try to use System.IO.File.Copy where the source is
"\\10.100.100.1\myfolder\test.txt"

When running the aspx file on the server (the server is
also the client) it works, but when using another NT
client it does not work.
The err.description says "Could not find file ..."
System.IO.File.Exists return false here.

But If I manually paste in \\10.100.100.1
\myfolder\test.txt in the IE address field and press "Go"
the file is found.

Strange or not?Hi,

I don't think that the default asp.net user got rights to access network
resources.

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!