http://blogs.msdn.com/b/pranavwagh/archive/2007/03/03/word-2007-file-seems-to-be-deleted-when-you-open-and-save-it-using-dsoframer.aspx

————————————————————————————————————————————————————————

This is one of the interesting cases I had lately. My customer was using DSOFramer sample to host Office Documents, but whenever he tried to open and save Word 2007 documents in this manner, guess what !! the file seems to be deleted !

As I am basically a VB guy I did not want to bother myself with VC++ code of DSOFramer, because I've had easier ways to troubleshoot. The first thing I tried was Process Monitor from sysinternals. I could see that we are moving the file to a temp directory and then while saving it we are saving the changes in it. hmm..strange!

Then I checked DSOFramer code and I realized that IPersist:Save() is returning S_OK, it doesn't look like there is some issue whatsoever. Then moved to Word 2007 code, to me it looks like a bug in the implementation of IPersist:Save().

So ..to tackle this I had to modify the code of DSOFramer a bit, being more precise I modified the code of "CDsoDocObject::SaveStorageToFile" [this is in source file dsofdocobj.cpp]. Here is the modified code:

if (SUCCEEDED(hr = m_pole->QueryInterface(IID_IPersistFile, (void**)&pipfile)))
{
//Get the current open file
LPWSTR pwszCurPath = new WCHAR(MAX_PATH+1);
pipfile->GetCurFile(&pwszCurPath);
//Perform save.
hr = pipfile->Save(pwszFile, FALSE);
pipfile->Release();
//Save results S_OK, but the document is saved to the original location (IPersistFile->GetCurFile) in Word 2007.
//We will just check if that's the case and move the file.
if (SUCCEEDED(hr) && !FFileExists(pwszFile))
{
//We should come here only in case of Word 2007.
CopyFileW(pwszCurPath, pwszFile, TRUE);
}
}

Ok..bye for now.. will be  back in a day with some more, and yes I am starting to do technorati and del.icio.us tagging

 
 
 
 
 
  • Asim Shah
    20 Mar 2007 3:09 AM

    I've tried this change in my version of the DSOFramer and I get a compile time error as there is no variable available called pwsxCurPath.

    I downloaded my source from the KB311765 link (same as the one you provide links to).

    Did you get your source from somewhere else?

    Asim Shah (asimshah@hotmail.com)

    Hey..i am sorry ..there was a typo in my code..i corrected it
     
  • Jag
    29 Mar 2007 2:42 AM

    Can someone please send to me the working dsoframer fixed to: jag_vb at. hotmail

    thnks

    Hello ..sir, nobody will send it to you. You 'll need to work on it! its a sample, provided as-is, and i am sorry there was a typo in my code, i corrected it
     
  • 1 Jan 2008 2:46 PM

    According to MSDN, IPersistFile::GetCurFile allocates the string buffer for you so I think there's a memory leak in your code.

    Here's what I believe to be correct (not yet tested though):

    //Get the current open file

    LPWSTR pwszCurPath = NULL;

    if (S_OK != pipfile->GetCurFile(&pwszCurPath))

    {

    pwszCurPath = NULL;

    }

    //Perform save.

    hr = pipfile->Save(pwszFile, FALSE);

    pipfile->Release();

    //Save results S_OK, but the document is saved to the original location (IPersistFile->GetCurFile) in Word 2007.

    //We will just check if that's the case and move the file.

    if (SUCCEEDED(hr) && !FFileExists(pwszFile) && pwszCurPath != NULL)

    {

    //We should come here only in case of Word 2007.

    CopyFileW(pwszCurPath, pwszFile, TRUE);

    }

    if (pwszCurPath != NULL)

    {

    CoTaskMemFree(pwszCurPath);

    pwszCurPath = NULL;

    }

http://blogs.msdn.com/b/pranavwagh/archive/2007/03/03/word-2007-file-seems-to-be-deleted-when-you-open-and-save-it-using-dsoframer.aspx的更多相关文章

  1. POI 读取word (word 2003 和 word 2007)(转,好用)

    POI 读取word (word 2003 和 word 2007)(转,好用) 转做的操作: 将作者文中失效的链接的正确链接放在失效链接的下面. 最近在给客户做系统的时候,用户提出需求,要能够导入 ...

  2. http://www.cnblogs.com/Lawson/archive/2012/09/03/2669122.html

    http://www.cnblogs.com/Lawson/archive/2012/09/03/2669122.html

  3. Word 2007 文档结构图混乱

    Word 2007在编写大型文档时经常出现文档结构图混乱的情况,经过多番检索试验,得出结论: 绝对有效的临时性解决方案:在打开word的时候左下角会有提示word自动更新文档样式,按esc键取消,然后 ...

  4. [转]彻底征服Word 2007标题多级列表

    [转]彻底征服Word 2007标题多级列表 用Word编写文档的人都知道,一篇长文档一般是需要分章节来划分段落的.在Word中也有对应的工具来完成这项任务,这就是多级列表.然而绝大多数使用Micro ...

  5. Windows XP和Word 2007不能正常使用VSTO插件

    今天帮助同事解决了一个小问题,就是在WindowsXP上,为Word2007开发的插件不能正常显示. 通过搜索关键词 WindowsXp Word 2007 VSTO找到了两个解决方案. http:/ ...

  6. POI 读取word (word 2003 和 word 2007) (转)

    最近在给客户做系统的时候,用户提出需求,要能够导入 word 文件,现在 microsoft word 有好几个版本 97.2003.2007的,这三个版本存储数据的格式上都有相当大的差别,而现在 9 ...

  7. http://www.cnblogs.com/Matrix54/archive/2012/05/03/2481260.html

    http://www.cnblogs.com/Matrix54/archive/2012/05/03/2481260.html

  8. Embedding Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office

    Download the sample code This visual how-to article presents a solution that creates a Word 2007 doc ...

  9. Word 2007 封面、目录和正文页码单独设置

    word 2007 生成目录比较简单,即使不会,也可以百度,很快就能弄好.现在有如下需求: 1.封面去掉页码 2.目录页码从1开始,页码在页脚底部中间位置,格式为[1] 3.正文也从1开始,页码在页脚 ...

随机推荐

  1. 谷歌的ajax.googleapis.com被墙导致访问很多国外网站很慢的解决方法

    比如访问StackOverflow, 更比如flexerasoftware.com(导致Visual Studio的打包程序InstallShield Limited Edition不能注册和下载) ...

  2. POJ 3254 (状压DP) Corn Fields

    基础的状压DP,因为是将状态压缩到一个整数中,所以会涉及到很多比较巧妙的位运算. 我们可以先把输入中每行的01压缩成一个整数. 判断一个状态是否有相邻1: 如果 x & (x << ...

  3. [转] POJ数学问题

    转自:http://blog.sina.com.cn/s/blog_6635898a0100magq.html 1.burnside定理,polya计数法 这个大家可以看brudildi的<组合 ...

  4. 13.Object-C--浅谈Foundation框架常用的结构体

    ------- android培训.iOS培训.期待与您交流! ---------- 昨天学习了Foundation框架中常用的结构体,下面我简单的总结一下,如果错误麻烦请留言指正,谢谢! Found ...

  5. Calculate drive total/free/available space

    using System; using System.Collections.Generic; using System.IO; using System.Text; namespace Consol ...

  6. (转)Spark 算子系列文章

    http://lxw1234.com/archives/2015/07/363.htm Spark算子:RDD基本转换操作(1)–map.flagMap.distinct Spark算子:RDD创建操 ...

  7. LoopBar – Tap酒吧与无限滚动

    相约 LoopBar – 标签栏与无限滚动为Android由Cleveroad 在Cleveroad我们最近认识到通过使用任何一个应用程序类别的导航,导航面板是很无聊和琐碎.这就是为什么我们的设计师的 ...

  8. MySQL与Oracle 差异比较之五存储过程&Function

    存储过程&Function 编号 类别 ORACLE MYSQL 注释 1 创建存储过程语句不同 create or replace procedure P_ADD_FAC(   id_fac ...

  9. 为什么从PhoneGap中逃离

    我是一名移动应用的开发者,从JAVA 为主的Android到以Objective-C为主的iOS最后到以HTML5为主的跨平台开发,我已经走过了五年多的时光,而我也从一个底层的码农成长为项目负责人. ...

  10. hdu 5492 Find a path(dp+少量数学)2015 ACM/ICPC Asia Regional Hefei Online

    题意: 给出一个n*m的地图,要求从左上角(0, 0)走到右下角(n-1, m-1). 地图中每个格子中有一个值.然后根据这些值求出一个最小值. 这个最小值要这么求—— 这是我们从起点走到终点的路径, ...