Why dsofile.dll still need Office Installation?

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

I wrote a small piece of code using the dsofile.dll component to modify document properties after upload a file to a web server (to set a guid to link the file to a database record). I took the component and intructions from here: http://support.microsoft.com/kb/224351

As far as I understanded it don't use Office to modify the properties. I implemented it and tested it on my 32 and 64 bit machine (webserver runs on 32bit mode) and all worked fine. I was happy. But after deploy it to a life machine it didn't persist the properties on my values, but don't throw any errors as well!

Here is some code to see what I did:

public void SetProperty(string filename, string property, string value) {   m_oDocument.Open(filename);    var oProp = m_oDocument.CustomProperties;   try   {     oProp.Add(property, value);   } catch(Exception)   {     foreach (CustomProperty cProp in oProp.Cast<CustomProperty>().Where(cProp => cProp.Name == property))     {       cProp.set_Value(value);     }   }   if ( Debug)   {     m_spy.Spy("filename: " + filename);     m_spy.Spy("filename modified: " + m_oDocument.IsDirty);   }    if ( m_oDocument.IsDirty ) m_oDocument.Save();   m_oDocument.Close();    if ( Debug ) m_spy.Spy(GetProperty(filename, property));  } 

So I started implement debug code, read articles on the web whole day long. I ended up installing Office 2010 32bit on the server.

Then after I got a new error:

The document is not an OLE file, and does not support extended document properties 

Strange thing the error was only for dotx, xlsx, ff, but not for doc, xls, ff.

After I installed all available updates for Office 2010 and retried. Then it worked as I wanted and persist the properties I set with the upload page on all files.

So installing Office 2010 as a must on a server isn't what I expected todo :)

  • Does anyone know what components of the Office installation the dsofile.dll need to work without a fill installation?
  • In other words: Can I copy a bunch of files and "register" them on the server manually?
  • Or did I misunderstand something and it is my code?!

回答1:

Strange thing the error was only for dotx, xlsx, ff, but not for doc, xls

This is by design. The dsofile sample only allows accessing files that use the OLE Structured Storage container format. OLE is a dead technology in general, Office was one of the last Microsoft products that still supported it. But that support has been disappearing quickly since the 2007 edition. It is gone for .dotx and .xlsx file formats as well, those are zipped XML files that follow the OpenXML specification. You can't access them with dsofile.

You'll need to go shopping for a better solution, there are many.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!