By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

dsolefile issues when file is open through share

P: n/a
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.

[NullReferenceException: Object reference not set to an instance of an
object.]
DSOleFile.DocumentProperties.get_Title() +0
DevIntraclean.FileListingwImage.Page_Load(Object sender, EventArgs
e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +731

I listed the code below:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'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.ReleaseComO bject(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.ReleaseComO bject(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.ReleaseComO bject(docProp)
End If
Next
Next
'Release com object or file will remain locked

If Not propReader Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(propReader)
End If
'Set Datalist datasource and bind
dlFileListing.DataSource = fileListTable
dlFileListing.DataBind()

End Sub
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.