Showing posts with label files. Show all posts
Showing posts with label files. Show all posts

Wednesday, March 28, 2012

System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning

I have an ASP.NET application which displays the directories & files in a
specified directory on the server. I use the
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() to
retrieve the lists of files and directories. I have two very similar
versions of this that I am debugging, both of which use the methods
mentioned above. However, one of them is returning the contents of the
specified directory and the other is returning the contents of the project's
directory. I have checked to see what values are used by and returned by
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles(), and
they use the values I expect, but do not return the directories and files in
that directory. What is going on here?"Nathan Sokalski" <njsokalski@.hotmail.comwrote in message
news:ehSNlnJ8HHA.5164@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

>I have an ASP.NET application which displays the directories & files in a
>specified directory on the server. I use the
>System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() to
>retrieve the lists of files and directories. I have two very similar
>versions of this that I am debugging, both of which use the methods
>mentioned above. However, one of them is returning the contents of the
>specified directory and the other is returning the contents of the
>project's directory. I have checked to see what values are used by and
>returned by System.IO.Directory.GetDirectories() and
>System.IO.Directory.GetFiles(), and they use the values I expect, but do
>not return the directories and files in that directory. What is going on
>here?


[X-posting removed]

Please show your code...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
On Sep 6, 11:23 am, "Nathan Sokalski" <njsokal...@.hotmail.comwrote:

Quote:

Originally Posted by

I have an ASP.NET application which displays the directories & files in a
specified directory on the server. I use the
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() to
retrieve the lists of files and directories. I have two very similar
versions of this that I am debugging, both of which use the methods
mentioned above. However, one of them is returning the contents of the
specified directory and the other is returning the contents of the project's
directory. I have checked to see what values are used by and returned by
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles(), and
they use the values I expect, but do not return the directories and files in
that directory. What is going on here?


Both of those methods work fine for me. You will need to post some
actual code that is having the problem.

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.Directory.GetFiles(path, searchPattern)

Hi

I don't know if this is the right place to put this post but I didn't found anywhere else.

The thing is that I'm getting files in a directory but I would like to pick only four types of files: .wmv, .avi, .mpeg and .mpg. I know that the search pattern works but I can only search for one type of file. Can extend the search to look for all 4 types?

Thx

It seems that there is no direct way to do this, really strange. Maybe you can get all files under the directory, and then use regular expression to get files of these types?

Hi

Thx for the reply. I already thought of that. I know it works cause I tried it. I just wanted another way to optimize unnecessary code. But thanks anyway lori_Jay

System.IO.FileNotFoundException, When Accessing file in remote ser

I am trying to access files in a remote server from my ASP.NET application,
it is giving System.IO.FileNotFoundException error. I tried mapping that
server location like "H:\ErrorLogs\error.log" still it gives error. I tried
even giving the server name and directory like
"\\server_name\\Directory\\file.log" still it gives file not found exception.
Does anyone help me fix this.

Thanksuse \\machineIP\sharename\filename

"Raja" <Raja@.discussions.microsoft.com> wrote in message
news:DC182C99-4D78-4A68-BEDC-632DDE49A827@.microsoft.com...
> I am trying to access files in a remote server from my ASP.NET
application,
> it is giving System.IO.FileNotFoundException error. I tried mapping that
> server location like "H:\ErrorLogs\error.log" still it gives error. I
tried
> even giving the server name and directory like
> "\\server_name\\Directory\\file.log" still it gives file not found
exception.
> Does anyone help me fix this.
> Thanks
asp.net normally does not have permission to any network resources. to
access a networked drive, you will have to make the asp_net account a domain
account, or specify the userName and password of a domain account in the web
config <impersonate> tag.

-- bruce (sqlwork.com)

"Raja" <Raja@.discussions.microsoft.com> wrote in message
news:DC182C99-4D78-4A68-BEDC-632DDE49A827@.microsoft.com...
> I am trying to access files in a remote server from my ASP.NET
application,
> it is giving System.IO.FileNotFoundException error. I tried mapping that
> server location like "H:\ErrorLogs\error.log" still it gives error. I
tried
> even giving the server name and directory like
> "\\server_name\\Directory\\file.log" still it gives file not found
exception.
> Does anyone help me fix this.
> Thanks

System.IO.FileNotFoundException, When Accessing file in remote ser

I am trying to access files in a remote server from my ASP.NET application,
it is giving System.IO.FileNotFoundException error. I tried mapping that
server location like "H:\ErrorLogs\error.log" still it gives error. I tried
even giving the server name and directory like
"\\server_name\\Directory\\file.log" still it gives file not found exception
.
Does anyone help me fix this.
Thanksuse \\machineIP\sharename\filename
"Raja" <Raja@.discussions.microsoft.com> wrote in message
news:DC182C99-4D78-4A68-BEDC-632DDE49A827@.microsoft.com...
> I am trying to access files in a remote server from my ASP.NET
application,
> it is giving System.IO.FileNotFoundException error. I tried mapping that
> server location like "H:\ErrorLogs\error.log" still it gives error. I
tried
> even giving the server name and directory like
> "\\server_name\\Directory\\file.log" still it gives file not found
exception.
> Does anyone help me fix this.
> Thanks
asp.net normally does not have permission to any network resources. to
access a networked drive, you will have to make the asp_net account a domain
account, or specify the userName and password of a domain account in the web
config <impersonate> tag.
-- bruce (sqlwork.com)
"Raja" <Raja@.discussions.microsoft.com> wrote in message
news:DC182C99-4D78-4A68-BEDC-632DDE49A827@.microsoft.com...
> I am trying to access files in a remote server from my ASP.NET
application,
> it is giving System.IO.FileNotFoundException error. I tried mapping that
> server location like "H:\ErrorLogs\error.log" still it gives error. I
tried
> even giving the server name and directory like
> "\\server_name\\Directory\\file.log" still it gives file not found
exception.
> Does anyone help me fix this.
> Thanks

System.IO: best approach for clearing a DIR of all files except .CSV

hiya,
I have a DIR that should only accept .CSV files..I haven't found a way to
do this prorgramatically.

ATM, I:
1) obtain an array of all the files that contain a .CSV extension.
2) move these files to another dir.

I check to see if there are any NON-CSV files in the dir by the following:

<code>
If arrAllFiles.Length = arrCsvFiles.Length Then
'do nothing, as this DIR only contained CSV files.
Else
'delete ALL the files in this dir, as the CSV files have already been
moved.
'The remaining files are therefore, NON-CSV
End If
<\code
Is this a good approach?Or maybe there is a slicker way to achieve what I
am trying to do / maybe there are some utilities out there that already do
all the system.IO stuff?

All thoughts appreciated.

many thanks
yogi

--
Message posted via http://www.dotnetmonster.comYou could also loop through all the files, checkif they EndsWith(".csv") if
not, delete them.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"chris yoker via DotNetMonster.com" <forum@.nospam.DotNetMonster.com> wrote
in message news:86e839cf6238492484f4c941524b48a4@.DotNetMonste r.com...
> hiya,
> I have a DIR that should only accept .CSV files..I haven't found a way to
> do this prorgramatically.
> ATM, I:
> 1) obtain an array of all the files that contain a .CSV extension.
> 2) move these files to another dir.
> I check to see if there are any NON-CSV files in the dir by the following:
> <code>
> If arrAllFiles.Length = arrCsvFiles.Length Then
> 'do nothing, as this DIR only contained CSV files.
> Else
> 'delete ALL the files in this dir, as the CSV files have already been
> moved.
> 'The remaining files are therefore, NON-CSV
> End If
> <\code>
> Is this a good approach?Or maybe there is a slicker way to achieve what I
> am trying to do / maybe there are some utilities out there that already do
> all the system.IO stuff?
> All thoughts appreciated.
> many thanks
> yogi
> --
> Message posted via http://www.dotnetmonster.com

System.IO: best approach for clearing a DIR of all files except .CSV

hiya,
I have a DIR that should only accept .CSV files..I haven't found a way to
do this prorgramatically.
ATM, I:
1) obtain an array of all the files that contain a .CSV extension.
2) move these files to another dir.
I check to see if there are any NON-CSV files in the dir by the following:
<code>
If arrAllFiles.Length = arrCsvFiles.Length Then
'do nothing, as this DIR only contained CSV files.
Else
'delete ALL the files in this dir, as the CSV files have already been
moved.
'The remaining files are therefore, NON-CSV
End If
<\code>
Is this a good approach?Or maybe there is a slicker way to achieve what I
am trying to do / maybe there are some utilities out there that already do
all the system.IO stuff?
All thoughts appreciated.
many thanks
yogi
Message posted via http://www.webservertalk.comYou could also loop through all the files, checkif they EndsWith(".csv") if
not, delete them.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"chris yoker via webservertalk.com" <forum@.nospam.webservertalk.com> wrote
in message news:86e839cf6238492484f4c941524b48a4@.Do
webservertalk.com...
> hiya,
> I have a DIR that should only accept .CSV files..I haven't found a way to
> do this prorgramatically.
> ATM, I:
> 1) obtain an array of all the files that contain a .CSV extension.
> 2) move these files to another dir.
> I check to see if there are any NON-CSV files in the dir by the following:
> <code>
> If arrAllFiles.Length = arrCsvFiles.Length Then
> 'do nothing, as this DIR only contained CSV files.
> Else
> 'delete ALL the files in this dir, as the CSV files have already been
> moved.
> 'The remaining files are therefore, NON-CSV
> End If
> <\code>
> Is this a good approach?Or maybe there is a slicker way to achieve what I
> am trying to do / maybe there are some utilities out there that already do
> all the system.IO stuff?
> All thoughts appreciated.
> many thanks
> yogi
> --
> Message posted via http://www.webservertalk.com

System.Messaging

Hello, I came across a tutorial on uploading files to a databaseand the example code given in it has the following code thatgives an error that says " Name 'Exc' is not declared.", when I build mysolution.

Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
 I'm trying to get up to speed with this dot net stuff by going through this and other tutorials. I have already added reference to the System.Messaging namespace to my application. What else must I do to make this work. Thank you in advance for your help.

You need an

Imports System.messaging
along with all the other Imports at the top of the program.