English 中文(简体)
不得在不设字眼的情况下开立字眼并提一下
原标题:Cannot open a word doc and reference it without locking it
  • 时间:2012-04-19 23:16:09
  •  标签:
  • c#-4.0
  • com

Hello I知道如何开放,并从一字档案中获取一线密码。 然而,我在这方面产生了不良后果。 话语已经锁定,我不知道如何分配正在锁定的。 我最终想开一个文件,把它放在联合国中心的道路上,并读到其中一部分,无论其他人是否开立,从中划线,最后一点,不拯救任何东西或锁定档案。 我最接近的是,我可以打开一个文件,把它 par起来,但当我打开并关闭文件时(使用该守则的机器)它会mag地打开。

我几乎不了解COM,因此我只得 while一 while,并发现了有关马歇尔的物品,并补充说。 我试图转而引用以下文字:真实的,阅读:法尔。 我认为,我只剩下一件简单的事情,因此我认为我在此要问。 任何建议都是免费的,我都在4.0英寸上 co,因此,在宣布放弃第j条=无效的所有建议中,你都没有通过,因此,第 ob条对开放《意见》无效。

 public static string ReadWordDoc(string loc)
{
Word.Application wordApp = new Word.Application();

Word.Document Doc = wordApp.Documents.Open(loc, ReadOnly: true);

sb = "";

foreach (Word.Paragraph objParagraph in Doc.Paragraphs)
{
try 
{
    sb += objParagraph.Range.Text + "
";
}
catch (Exception ex)
{
    throw ex;
}
}

return sb;

Doc.Close(SaveChanges: false);

Marshal.ReleaseComObject(Doc);

wordApp.Quit(SaveChanges: false);

}
最佳回答

由于某种原因,我发现,有人关着一个锁。 我确信,我与“不拯救变革”组织一样,也管理垃圾收集器。 这可能是微乎其微的,但从根本上来说,它确保我所选择的档案中没有锁。

Word._Application wordApp = new Word.Application();
    Word._Document Doc = wordApp.Documents.Open(loc, ReadOnly: true);
        try
        {
            sb = "";

            foreach (Word.Paragraph objParagraph in Doc.Paragraphs)
            {
                try
                {
                    sb += objParagraph.Range.Text + "
";
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        catch (COMException) { }
        finally
        {
            //FileInfo finfo = new FileInfo(loc);
            //finfo.IsReadOnly = false;

            if (Doc != null)
            {
                Doc.Close();
                Doc = null;
            }
            if (wordApp != null)
            {
                wordApp.Quit(Word.WdSaveOptions.wdDoNotSaveChanges);
                wordApp = null;
            }
        }

        GC.Collect();
        GC.WaitForPendingFinalizers();

        GC.Collect();
        GC.WaitForPendingFinalizers();

        return sb;
问题回答

暂无回答




相关问题
How can i add a button to all windows explorer instances?

I am trying to add a button to one of the existing tool bars in any windows explorer instance. After much research i figured out that BHO (browser helper objects) are the best way to hook to ...

Hunting memory leaks

I m finding leaked heap blocks by using the following command in WinDbg !heap –l With each leaked heap block I get, I m running to following to get the stack trace. !heap -p -a leakedheapblock The ...

Why use CComBSTR instead of just passing a WCHAR*?

I m new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this ...

IThumbnailProvider and IInitializeWithItem

I am trying to develop an IThumbnailProvider for use in Windows 7. Since this particular thumbnail would also be dependant on some other files in the same directory, I need to use something other than ...

Getting a byte array from out of process C++ COM to C#

What s the best way to get a chunk of memory (i.e. void*) from a COM server to C#? We have been using an IStream (using CreateStreamOnHGlobal) and passing that back, which worked. However when we ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

热门标签