TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
gerald.weibl
NA
2
0
Free a document!
Aug 27 2004 4:55 AM
Hallo! I am writing a Web Application in C#. I use dsofile.dll to get the Custom Properties of Office Documents. Tha functions very well. But when i reload my page I get an Error message. Here is my Code: [CODE] protected System.Web.UI.WebControls.Table myTable; protected DSOleFile.CustomProperties custProps; protected DSOleFile.PropertyReader objPropReader; protected DSOleFile.DocumentProperties objDocumentProps; private void Page_Load(object sender, System.EventArgs e) { try { string strDirectory = @"c:\temp"; objPropReader = new DSOleFile.PropertyReaderClass(); ArrayList arrListDocumentFullName = new ArrayList(); ArrayList arrListDocumentName = new ArrayList(); DirectoryInfo di = new DirectoryInfo(strDirectory); FileInfo[] rgFiles = di.GetFiles("*.doc"); foreach(FileInfo objFileInfo in rgFiles) { System.IO.FileAttributes objAttrFile = System.IO.File.GetAttributes(objFileInfo.FullName); if ((objAttrFile & (System.IO.FileAttributes.Hidden | System.IO.FileAttributes.System)) != 0) { Response.Write(objFileInfo.Name + ": Hidden Datei
"); } else { arrListDocumentFullName.Add(objFileInfo.FullName); arrListDocumentName.Add(objFileInfo.Name); } } int intPropCount = 0; object[] objIndex; string strSharePath = @"\\wlcomgtd\temp\"; string strFileName = ""; string strValue = ""; for(int i = 0; i < arrListDocumentFullName.Count; i++) { strFileName = arrListDocumentFullName[i].ToString(); objDocumentProps = objPropReader.GetDocumentProperties(strFileName); System.Runtime.InteropServices.Marshal.ReleaseComObject(objPropReader); objPropReader = null; intPropCount = objDocumentProps.CustomProperties.Count; objIndex = new object[intPropCount]; object obj = null; TableRow row = new TableRow(); TableCell cellName = new TableCell(); cellName.Text = "
" + arrListDocumentName[i].ToString() + "
"; cellName.RowSpan = 2; cellName.BackColor = Color.White; row.Cells.Add(cellName); for(int a = 1; a < intPropCount+1; a++) { obj = a; objIndex[a-1] = objDocumentProps.CustomProperties[obj].Name; TableCell cellPropName = new TableCell(); cellPropName.Text = objDocumentProps.CustomProperties[obj].Name; row.Controls.Add(cellPropName); } row.BackColor = Color.LightGray; myTable.Rows.Add(row); TableRow row1 = new TableRow(); for(int y = 0; y < intPropCount; y++) { // strValue = "Nicht vorhanden"; custProps = objDocumentProps.CustomProperties; strValue = objDocumentProps.CustomProperties[objIndex[y]].get_Value().ToString(); TableCell cell2 = new TableCell(); cell2.Text = strValue; row1.Cells.Add(cell2); } myTable.Rows.Add(row1); } System.Runtime.InteropServices.Marshal.ReleaseComObject(objDocumentProps); objDocumentProps = null; GC.Collect(); GC.WaitForPendingFinalizers(); } catch(System.Runtime.InteropServices.COMException ex) { Response.Write(ex.ToString()); } } [/CODE] An this is the error Message which occurs when i wanna reload the page: System.Runtime.InteropServices.COMException (0x80030020): A share violation has occured at DSOleFile.PropertyReaderClass.GetDocumentProperties(String sFileName) at Documentproperties.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\documentproperties\webform1.aspx.cs:line 65 I found out that the Process aspnet_wp.exe is locking the Document. When I kill the process manually from the Task Manager I can open the document. How can I implement that, after the Custom Properties have been read, the document is free again? I hope you can help me. Thanks, Gerald.
Reply
Answers (
0
)
cobol to vb.net conversion
get source code