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. 新版本 JSAPI微信支付V3 C# DEMO

    小弟在公众号后台无意中点了更新(微信支付接口升级)PS:想都没有想,心里还乐滋滋的免费的干嘛不升级...后果来了.面临着支付不能用了,代码需要重新更新. /** * JS_API支付demo * == ...

  2. XML中对特殊字符的处置

    str = str.replaceAll("‘", "‘"); str = str.replaceAll("’", "‘" ...

  3. 通过运行时动态给OC分类添加属性

    #import <UIKit/UIKit.h> /** iOS 开发中,分类默认不允许保存属性 如果在分类中,定义一个属性,需要自己实现 getter & setter 方法,而且 ...

  4. POJ 3422 Kaka's Matrix Travels (K取方格数:最大费用流)

    题意 给出一个n*n大小的矩阵,要求从左上角走到右下角,每次只能向下走或者向右走并取数,某位置取过数之后就只为数值0,现在求解从左上角到右下角走K次的最大值. 思路 经典的费用流模型:K取方格数. 构 ...

  5. 关于ios越狱开发的那些事

    也许吧,每每接触某些新东西的时候,都有点犯晕吧,这不是应该要的. 第一次接触ios越狱开发,也是这样吧.这篇主要是从无到有的说一下ios越狱的开发,网上很多的教程大部门都比较旧了吧,放在新设备上总是出 ...

  6. POJ2236 Wireless Network

    解题思路:简单并查集,注意时间限制是10000MS,每次进行O操作之后,   进行一次for循环,进行相关调整.同时注意输入输出格式,见代码: #include<cstdio> #incl ...

  7. 大数据时代的技术hive:hive介绍

    我最近研究了hive的相关技术,有点心得,这里和大家分享下. 首先我们要知道hive到底是做什么的.下面这几段文字很好的描述了hive的特性: 1.hive是基于Hadoop的一个数据仓库工具,可以将 ...

  8. 【转】Github轻松上手5-站在巨人的肩膀上(Fork)

    转自:http://blog.sina.com.cn/s/blog_4b55f6860100zzj3.html 有时候你可能想给别人的项目出把力,或者想以别人的项目作为自己项目的起点,在Github里 ...

  9. jQuery - 实时统计输入框输入个数(中文输入法适用)

    经常在实时统计文本框输入多少字的时候,有时会出现不及时统计,特别是在中文输入法下. 为了实时准确统计,可以修改代码如下:     $(function() {        $("#txtT ...

  10. dubbo-admin在jdk 1.8上部署出错问题

    今天在linux上部署dubbo-admin-2.5.4,一直报错: ERROR context.ContextLoader - Context initialization failedorg.sp ...