I am listing the contents of a directory, everything seems to work
fine. However, I created a share to the folder in the web for content
management purposes. When any user opens the file in the share the
following code fails due to permissions.
'Set the Image for the Page
headerImage.ImageUrl = ImagePath
'Create Datatable to Hold File Information
Dim fileListTable As New DataTable
Dim fileListRow As DataRow
fileListTable.Columns.Add("Name")
fileListTable.Columns.Add("Title")
fileListTable.Columns.Add("LastModified")
fileListTable.Columns.Add("CreateDate")
fileListTable.Columns.Add("docIcon")
'Create Arraylist of OLE File Types
Dim fileOleTypeList As New ArrayList
fileOleTypeList.Add("*.doc")
fileOleTypeList.Add("*.xls")
'Declarations
'ToDo: Commented out the DSOLeFile Line
Dim propReader As New DSOleFile.PropertyReader
Dim docProp As DSOleFile.DocumentProperties
Dim i As Integer
'ToDo: Remove this After Location Property Works
Dim docDirectors As New DirectoryInfo(Location)
'Loop Through Array List for OLE Objects
For i = 0 To fileOleTypeList.Count - 1
'Loop Through Each File in Folder Directory
For Each file As System.IO.FileInfo In
docDirectors.GetFiles(fileOleTypeList.Item(i))
fileListRow = fileListTable.NewRow
Try
docProp =
propReader.GetDocumentProperties(file.FullName)
Catch ex As Exception
Dim aLog As EventLog
Dim sMessage As String
aLog = New EventLog
aLog.Source = "DevIntracleanLocal"
sMessage = ex.Message & " File: " & file.FullName
aLog.WriteEntry(sMessage, EventLogEntryType.Error)
End Try
'Gather File Name for Display
fileListRow.Item("Name") = VirtualPath & "" &
file.Name
'Gather File Last Modified for Display
fileListRow.Item("LastModified") = file.LastWriteTime
'Check to See If document Properties are Valid
If Not docProp Is Nothing Then
'Gather the Document Title if Available for
Display
If docProp.Title <> "" Then
fileListRow.Item("Title") = docProp.Title
Else
fileListRow.Item("Title") = Replace(file.Name,
file.Extension, "")
End If
'Gather File Create Date for Display
'fileListRow.Item("CreateDate") =
file.CreationTime
'Gather Image that Matches File Extension for
Display
fileListRow.Item("docIcon") =
GetDocumentIconImage(file)
Else
'Gather the Document Title if Available for
Display use Fill Full Name If OLE not Available
fileListRow.Item("Title") = file.FullName
'Gather File Create Date for Display
'fileListRow.Item("CreateDate") =
file.CreationTime
'Gather Image that Matches File Extension for
Display
fileListRow.Item("docIcon") =
GetDocumentIconImage(file)
End If
'Release the com object or File Will Remain Locked
If Not docProp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(docProp)
End If
'Add File Properties Row to DataTable
fileListTable.Rows.Add(fileListRow)
Next
Next
'Release Com object or Files will remain Locked
If Not propReader Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(propReader)
End If
'Create Arraylist for non OLE Objects
Dim fileTypeList As New ArrayList
fileTypeList.Add("*.htm")
fileTypeList.Add("*.html")
fileTypeList.Add("*.pdf")
fileTypeList.Add("*.ppt")
'Loop Through Non Ole File Types
For i = 0 To fileTypeList.Count - 1
'Loop Through each file in folder matching search criteria
For Each file As FileInfo In
docDirectors.GetFiles(fileTypeList.Item(i))
'Create New Row in Datatable
fileListRow = fileListTable.NewRow
'Gather File Name for Link
fileListRow.Item("Name") = VirtualPath & "/" &
file.Name
'Gather File Last Modified Date to Display
fileListRow.Item("LastModified") = file.LastWriteTime
'Gather File Name and Remove extension to Display
fileListRow.Item("Title") = Replace(file.Name,
file.Extension, "")
'Gather Create Date for Display
'fileListRow.Item("CreateDate") = file.CreationTime
'Gather Image that Matches File Extension for Display
fileListRow.Item("docIcon") =
GetDocumentIconImage(file)
'Add Row to Datatable
fileListTable.Rows.Add(fileListRow)
'Release com object or file will remain locked
If Not docProp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(docProp)
End If
Next
Next
'Release com object or file will remain locked
If Not propReader Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(propReader)
End If
'Set Datalist datasource and bind
dlFileListing.DataSource = fileListTable
dlFileListing.DataBind()
|