I am experiencing problems when one user has a document open through a
share pointing to the web site. I use the dsolefile to read the
contents of a particular directory and then display them in a
datalist. When the next user selects trys to run the page, the page
fails and I get a generic error message from the stack trace. I am
assuming that the document properties cannot be read when a file is
open, but it worked well in asp.
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
DSOleFile.Docum entProperties.g et_Title() +0
DevIntraclean.F ileListingwImag e.Page_Load(Obj ect sender, EventArgs
e)
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.C ontrol.LoadRecu rsive() +98
System.Web.UI.C ontrol.LoadRecu rsive() +98
System.Web.UI.P age.ProcessRequ estMain() +731
I listed the code below:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Set the Image for the Page
headerImage.Ima geUrl = ImagePath
'Create Datatable to Hold File Information
Dim fileListTable As New DataTable
Dim fileListRow As DataRow
fileListTable.C olumns.Add("Nam e")
fileListTable.C olumns.Add("Tit le")
fileListTable.C olumns.Add("Las tModified")
fileListTable.C olumns.Add("Cre ateDate")
fileListTable.C olumns.Add("doc Icon")
'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.Prope rtyReader
Dim docProp As DSOleFile.Docum entProperties
Dim i As Integer
'ToDo: Remove this After Location Property Works
Dim docDirectors As New DirectoryInfo(L ocation)
'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.FileI nfo In
docDirectors.Ge tFiles(fileOleT ypeList.Item(i) )
fileListRow = fileListTable.N ewRow
Try
docProp =
propReader.GetD ocumentProperti es(file.FullNam e)
Catch ex As Exception
Dim aLog As EventLog
Dim sMessage As String
aLog = New EventLog
aLog.Source = "DevIntracleanL ocal"
sMessage = ex.Message & " File: " & file.FullName
aLog.WriteEntry (sMessage, EventLogEntryTy pe.Error)
End Try
'Gather File Name for Display
fileListRow.Ite m("Name") = VirtualPath & "" &
file.Name
'Gather File Last Modified for Display
fileListRow.Ite m("LastModified ") = file.LastWriteT ime
'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.Ite m("Title") = docProp.Title
Else
fileListRow.Ite m("Title") = Replace(file.Na me,
file.Extension, "")
End If
'Gather File Create Date for Display
'fileListRow.It em("CreateDate" ) =
file.CreationTi me
'Gather Image that Matches File Extension for
Display
fileListRow.Ite m("docIcon") =
GetDocumentIcon Image(file)
Else
'Gather the Document Title if Available for
Display use Fill Full Name If OLE not Available
fileListRow.Ite m("Title") = file.FullName
'Gather File Create Date for Display
'fileListRow.It em("CreateDate" ) =
file.CreationTi me
'Gather Image that Matches File Extension for
Display
fileListRow.Ite m("docIcon") =
GetDocumentIcon Image(file)
End If
'Release the com object or File Will Remain Locked
If Not docProp Is Nothing Then
System.Runtime. InteropServices .Marshal.Releas eComObject(docP rop)
End If
'Add File Properties Row to DataTable
fileListTable.R ows.Add(fileLis tRow)
Next
Next
'Release Com object or Files will remain Locked
If Not propReader Is Nothing Then
System.Runtime. InteropServices .Marshal.Releas eComObject(prop Reader)
End If
'Create Arraylist for non OLE Objects
Dim fileTypeList As New ArrayList
fileTypeList.Ad d("*.htm")
fileTypeList.Ad d("*.html")
fileTypeList.Ad d("*.pdf")
fileTypeList.Ad d("*.ppt")
'Loop Through Non Ole File Types
For i = 0 To fileTypeList.Co unt - 1
'Loop Through each file in folder matching search criteria
For Each file As FileInfo In
docDirectors.Ge tFiles(fileType List.Item(i))
'Create New Row in Datatable
fileListRow = fileListTable.N ewRow
'Gather File Name for Link
fileListRow.Ite m("Name") = VirtualPath & "/" &
file.Name
'Gather File Last Modified Date to Display
fileListRow.Ite m("LastModified ") = file.LastWriteT ime
'Gather File Name and Remove extension to Display
fileListRow.Ite m("Title") = Replace(file.Na me,
file.Extension, "")
'Gather Create Date for Display
'fileListRow.It em("CreateDate" ) = file.CreationTi me
'Gather Image that Matches File Extension for Display
fileListRow.Ite m("docIcon") =
GetDocumentIcon Image(file)
'Add Row to Datatable
fileListTable.R ows.Add(fileLis tRow)
'Release com object or file will remain locked
If Not docProp Is Nothing Then
System.Runtime. InteropServices .Marshal.Releas eComObject(docP rop)
End If
Next
Next
'Release com object or file will remain locked
If Not propReader Is Nothing Then
System.Runtime. InteropServices .Marshal.Releas eComObject(prop Reader)
End If
'Set Datalist datasource and bind
dlFileListing.D ataSource = fileListTable
dlFileListing.D ataBind()
End Sub