WCM - Das österreichische Computer Magazin Forenübersicht
 

Zurück   WCM Forum > Rat & Tat > Programmierung

Programmierung Rat & Tat für Programmierer

Microsoft KARRIERECAMPUS

Antwort
 
Themen-Optionen Ansicht
Alt 27.08.2004, 09:55   #1
Daywalker23
Jr. Member
 
Registriert seit: 10.08.2004
Alter: 44
Beiträge: 33


Standard Dokument wieder freigeben

Hallo!
Ich verwende die dsofile.dll um mir Custom Properties von Office Dokumenten anzeigen zu lassen. Das funktioniert einwandfrei. Nur wenn ich die Seite aktualisiere bekomme ich eine Fehlermeldung.

Ich zeig euch mal den Code den ich verwende:

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 = "<a href =" + strSharePath + arrListDocumentName[i].ToString() + ">" + arrListDocumentName[i].ToString() + "</a>";					
					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());
			}				
		}
Und hier die Fehlermeldung wenn ich auf aktualisieren klicke:
System.Runtime.InteropServices.COMException (0x80030020): Freigabeverletzung aufgetreten at DSOleFile.PropertyReaderClass.GetDocumentPropertie s(String sFileName) at Documentproperties.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\documentproperties\webform1.asp x.cs:line 65

Und zwar lockt der Prozess aspnet_wp.exe die Dokumente. Wenn ich den Prozess beende dann kann ich das Dokument wieder öffnen.

Wie kann ich das nun implementieren dass nachdem die Properties eines Dokumentes ausgelesen wurden das Dokument wieder freigegeben wird?

Hoffe ihr könnt mir helfen.

Danke, Gerald.
Daywalker23 ist offline   Mit Zitat antworten
Alt 27.08.2004, 22:04   #2
Biri
Hero
 
Registriert seit: 04.09.2001
Beiträge: 894


Standard

...das ist wohl etwas aufwändiger, weil ich es erst mal selbst ausprobieren müsste und dazu im moment keine zeit hab - ev. am sa. oder so.

btw. "aspnet_wp.exe" ist der asp.net workerprocess, also der welcher alle requests bearbeitet - wenn du diesen beendest, wird er automatisch neu gestartet und alle resourcen natürlich freigegeben.

welche version von .net verwendest du + welche entwicklungsumgebung ?
glaub, da mal gelesen zu haben, dass es mit dem von vs 2002 erzeugten code probleme bei com interop geben kann.

müsste da aber auch noch im netz recherchieren.

fg
-hannes
Biri ist offline   Mit Zitat antworten
Alt 30.08.2004, 09:01   #3
Daywalker23
Jr. Member
 
Registriert seit: 10.08.2004
Alter: 44
Beiträge: 33


Standard

Hallo!

Hab das Problem schon gelöst.

Danke,

Gerald.
Daywalker23 ist offline   Mit Zitat antworten
Alt 30.08.2004, 09:55   #4
Potassium
Inventar
 
Registriert seit: 06.03.2003
Alter: 37
Beiträge: 3.954

Mein Computer

Standard

Zitat:
Original geschrieben von Daywalker23
Hallo!

Hab das Problem schon gelöst.

Danke,

Gerald.
wäre nett wenn du auch verräts wie, damit auch andere leute die das problem haben eine lösung finden
Potassium ist offline   Mit Zitat antworten
Alt 01.09.2004, 15:29   #5
Daywalker23
Jr. Member
 
Registriert seit: 10.08.2004
Alter: 44
Beiträge: 33


Standard

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 = "<a href =" + strSharePath + arrListDocumentName[i].ToString() + ">" + arrListDocumentName[i].ToString() + "</a>";					
					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());
			}				
		}					
				}
Einfach das releasen des Objektes in die Schleife tun, damit nach jedem Schleifendurchlauf das Objekt wieder freigegeben wird.

Mfg

Gerald
Daywalker23 ist offline   Mit Zitat antworten
Antwort


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 21:51 Uhr.


Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Forum SEO by Zoints
© 2009 FSL Verlag