Microsoft office cannot open this file because some parts are missing or invalid как исправить

Is your screen showing the error message - Microsoft Office cannot open this file because some parts are missing or invalid when you try to open an old file? Do not worry because we have got the right solutions for you! If you have corrupted Office files, turn to EaseUS file repair software and you can get the corrupted Word, Excel, PPT, and PDF files back with simple steps. Read on to solve your problem.

Despite some shortcomings, Microsoft Word is the most widely used word processing program among the competitors. For example, if you try to open an old file in the new Microsoft Office, it might fail to open. It can be due to version incompatibility, or the file might be corrupted.

The Microsoft Word file you’re trying to open might be damaged, and you will get an error message stating, The file is corrupt and cannot be opened. This is followed by the message, Microsoft Office cannot open this file because some parts are missing or invalid. However, this article will provide you with methods for resolving this issue!

Workable Solutions Step-by-step Troubleshooting
1. Update Trust Center Settings
  1. Open MS Word on your computer.
  2. Select «File» and then «Options».
  3. Select «Trust Center»…Full steps
2. Change Security Settings
  1. Open the search bar, type dcomcnfg.
  2. Choose «Component Services».
  3. Double-click on the «Computers» folder…Full steps

Symptoms — Microsoft Office Cannot Open This File

The error message Microsoft Office cannot open this file because some parts are missing or invalid appears when you attempt to access a document written in a previous version of the software, such as 2007 or 2003.

Damaged File

It is common for this error message to appear after an update or when a problem arises during the saving process. If your computer loses power or crashes while you’re saving a file or while MS Word is writing to the disk, there’s a big chance that the file may get damaged.

Malfunctioning Storage or Malware

Most recent versions of Microsoft Word have reduced corruption by AutoSaving to a new place rather than saving on top of the currently opened document. Even if you follow all of the safety steps, you may still get these disappointing warnings indicating that a Word file has been corrupted or damaged.

The unexpected behavior might be linked to malfunctioning regions of your storage device in some instances. Additionally, malware threats may result in faulty Word files, mainly when the malware is so severe that it causes a system failure and tampers with the file.

To avoid this, make sure you back up your data regularly. You may get disappointed when you cannot view an important document. However, you shouldn’t be concerned about it too much since we will teach you how to fix damaged Word files in the next section.

Microsoft office cannot open this file because some parts are missing or invalid

Fix Microsoft Office Cannot Open This File Because Some Parts Are Missing or Invalid

Let’s look at two Word file repair procedures that you may use right now to get your files back in order and resolve this error that you are seeing. Among these methods, one requires updating Trust Center Settings, and the other involves modifying system configurations. Let’s proceed!

Method 1. Update Trust Center Settings

Recent versions of Microsoft Word have a stricter security policy regarding copied or downloaded files; thus, you should update your Trust Center settings to reflect this. You may have difficulties opening a Word document if you have enabled the Enabled Protected View options. You need to update the policy, which is something you already have. Here’s how it’s done.

Step 1. Open MS Word on your computer.

Step 2. Select «File» and then «Options» from the drop-down menu.

Step 3. Select «Trust Center» from the drop-down menu and hit the «trust Center settings» button.

Fix Microsoft office cannot open this file because some parts are missing or invalid-1

Step 4. Select «Protected View» from the drop-down menu.

fix Microsoft office cannot open this file because some parts are missing or invalid - 2

Step 5. Un-tick everything and hit the «OK» button to confirm your selection.

fix Microsoft office cannot open this file because some parts are missing or invalid - 3

Step 6. Now try opening the document again after restarting Microsoft Word

Likely, everything went well, and you should now be able to access the document without seeing the error notice Microsoft office cannot open this file because some parts are missing or invalid.”

Method 2. Change Component Security Settings

Modifying the Component Securityoptions in Microsoft Office is another approach to resolve the Microsoft Office error. If your document is stopped from launching by the Windows security level, you will need to reset the Component Security settings to their default values. Follow the simple steps below.

Step 1. Open the search bar, type dcomcnfg, and press the Enter key.

change component security -1

Step 2. A new window will appear. Choose «Component Services» from the menu.

Step 3. Double-click on the «Computers» folder on the main window of the screen.

change component security -2

Step 4. You should now view the «My Computer» icon. Right-click on it and pick «Properties» from the drop-down menu.

change component security -3

Step 5. Select the «Default Properties» option from the drop-down menu.

change component security -4

Step 6. Edit the «Default Distributed Properties» tab by selecting «Default» from the drop-down option under Default Distributed Com Communication Properties.

Step 7. Select the «OK» button and choose «Identity» from the Default impersonation level drop-down list.

change component security -5

How to Repair Corrupt Word Files with a File Repair Tool

If none of the previous approaches prove to be productive, we have created a Microsoft Office repair guide that uses the EaseUS Data Recovery Wizard to help you fix the problem. Hopefully, you’ll be able to discover how to repair documents and, in the end, restore your presumedly deleted data.

The tool may securely assist you in recovering files that have been damaged while also retaining the document’s formatting and style in the way it was created. There is no need to be concerned about compatibility. It may be used to recover Word documents generated in Word 2000 and earlier, including 2013. Since the support for this program is so clearly documented, you will appreciate the fact that you can get help quickly.

This easy-to-use tool can repair a word document without affecting any of its parts, such as photographs, fonts, initial text, links, headers, or footers, and it does not need the use of any other program to do this. 

Since it is a free online tool that you may use to explore, it is highly recommended that you install it from its official site and get familiar with the software’s excellent features before purchasing it.

Step 1. Launch EaseUS Data Recovery Wizard, and then scan disk with corrupted documents. This software enables you to fix damaged Word, Excel, PPT, and PDF files in same steps. 

select the disk with corrupted documents

Step 2. EaseUS data recovery and repair tool will scan for all lost and corrupted files. You can find the target files by file type or type the file name in the search box. 

find corrupted documents

Step 3. EaseUS Data Recovery Wizard can repair your damaged documents automatically. After file preview, you can click «Recover» to save the repaired Word, Excel, and PDF document files to a safe location.

repair corrrupt documents

Conclusion

Everything you need to know about how to fix Microsoft Office cannot open this file because some parts are missing or invalid has been provided to you in this article. This article also introduces the file repair tool as a third-party solution. Using this tool, you may fix damaged Microsoft Office documents. We hope our solutions are of great help to you. Have a good read!

Despite some shortcomings, Microsoft Word is the most widely used word processing program among the competitors. For example, if you try to open an old file in the new Microsoft Office, it might fail to open. It can be due to version incompatibility, or the file might be corrupted.

The Microsoft Word file you’re trying to open might be damaged, and you will get an error message stating, The file is corrupt and cannot be opened. This is followed by the message, Microsoft Office cannot open this file because some parts are missing or invalid. However, this article will provide you with methods for resolving this issue!

Workable Solutions Step-by-step Troubleshooting
1. Update Trust Center Settings
  1. Open MS Word on your computer.
  2. Select «File» and then «Options».
  3. Select «Trust Center»…Full steps
2. Change Security Settings
  1. Open the search bar, type dcomcnfg.
  2. Choose «Component Services».
  3. Double-click on the «Computers» folder…Full steps

Symptoms — Microsoft Office Cannot Open This File

The error message Microsoft Office cannot open this file because some parts are missing or invalid appears when you attempt to access a document written in a previous version of the software, such as 2007 or 2003.

Damaged File

It is common for this error message to appear after an update or when a problem arises during the saving process. If your computer loses power or crashes while you’re saving a file or while MS Word is writing to the disk, there’s a big chance that the file may get damaged.

Malfunctioning Storage or Malware

Most recent versions of Microsoft Word have reduced corruption by AutoSaving to a new place rather than saving on top of the currently opened document. Even if you follow all of the safety steps, you may still get these disappointing warnings indicating that a Word file has been corrupted or damaged.

The unexpected behavior might be linked to malfunctioning regions of your storage device in some instances. Additionally, malware threats may result in faulty Word files, mainly when the malware is so severe that it causes a system failure and tampers with the file.

To avoid this, make sure you back up your data regularly. You may get disappointed when you cannot view an important document. However, you shouldn’t be concerned about it too much since we will teach you how to fix damaged Word files in the next section.

Microsoft office cannot open this file because some parts are missing or invalid

Fix Microsoft Office Cannot Open This File Because Some Parts Are Missing or Invalid

Let’s look at two Word file repair procedures that you may use right now to get your files back in order and resolve this error that you are seeing. Among these methods, one requires updating Trust Center Settings, and the other involves modifying system configurations. Let’s proceed!

Method 1. Update Trust Center Settings

Recent versions of Microsoft Word have a stricter security policy regarding copied or downloaded files; thus, you should update your Trust Center settings to reflect this. You may have difficulties opening a Word document if you have enabled the Enabled Protected View options. You need to update the policy, which is something you already have. Here’s how it’s done.

Step 1. Open MS Word on your computer.

Step 2. Select «File» and then «Options» from the drop-down menu.

Step 3. Select «Trust Center» from the drop-down menu and hit the «trust Center settings» button.

Fix Microsoft office cannot open this file because some parts are missing or invalid-1

Step 4. Select «Protected View» from the drop-down menu.

fix Microsoft office cannot open this file because some parts are missing or invalid - 2

Step 5. Un-tick everything and hit the «OK» button to confirm your selection.

fix Microsoft office cannot open this file because some parts are missing or invalid - 3

Step 6. Now try opening the document again after restarting Microsoft Word

Likely, everything went well, and you should now be able to access the document without seeing the error notice Microsoft office cannot open this file because some parts are missing or invalid.”

Method 2. Change Component Security Settings

Modifying the Component Securityoptions in Microsoft Office is another approach to resolve the Microsoft Office error. If your document is stopped from launching by the Windows security level, you will need to reset the Component Security settings to their default values. Follow the simple steps below.

Step 1. Open the search bar, type dcomcnfg, and press the Enter key.

change component security -1

Step 2. A new window will appear. Choose «Component Services» from the menu.

Step 3. Double-click on the «Computers» folder on the main window of the screen.

change component security -2

Step 4. You should now view the «My Computer» icon. Right-click on it and pick «Properties» from the drop-down menu.

change component security -3

Step 5. Select the «Default Properties» option from the drop-down menu.

change component security -4

Step 6. Edit the «Default Distributed Properties» tab by selecting «Default» from the drop-down option under Default Distributed Com Communication Properties.

Step 7. Select the «OK» button and choose «Identity» from the Default impersonation level drop-down list.

change component security -5

How to Repair Corrupt Word Files with a File Repair Tool

If none of the previous approaches prove to be productive, we have created a Microsoft Office repair guide that uses the EaseUS Data Recovery Wizard to help you fix the problem. Hopefully, you’ll be able to discover how to repair documents and, in the end, restore your presumedly deleted data.

The tool may securely assist you in recovering files that have been damaged while also retaining the document’s formatting and style in the way it was created. There is no need to be concerned about compatibility. It may be used to recover Word documents generated in Word 2000 and earlier, including 2013. Since the support for this program is so clearly documented, you will appreciate the fact that you can get help quickly.

This easy-to-use tool can repair a word document without affecting any of its parts, such as photographs, fonts, initial text, links, headers, or footers, and it does not need the use of any other program to do this. 

Since it is a free online tool that you may use to explore, it is highly recommended that you install it from its official site and get familiar with the software’s excellent features before purchasing it.

Step 1. Launch EaseUS Data Recovery Wizard, and then scan disk with corrupted documents. This software enables you to fix damaged Word, Excel, PPT, and PDF files in same steps. 

select the disk with corrupted documents

Step 2. EaseUS data recovery and repair tool will scan for all lost and corrupted files. You can find the target files by file type or type the file name in the search box. 

find corrupted documents

Step 3. EaseUS Data Recovery Wizard can repair your damaged documents automatically. After file preview, you can click «Recover» to save the repaired Word, Excel, and PDF document files to a safe location.

repair corrrupt documents

Conclusion

Everything you need to know about how to fix Microsoft Office cannot open this file because some parts are missing or invalid has been provided to you in this article. This article also introduces the file repair tool as a third-party solution. Using this tool, you may fix damaged Microsoft Office documents. We hope our solutions are of great help to you. Have a good read!

Download PC Repair Tool to quickly find & fix Windows errors automatically

You may get an error prompt displaying the error message Microsoft Office cannot open this file because some parts are missing or invalid when you try to open a Word document or any other Office document on your Windows 11 or Windows 10 computer. This post provides the applicable solutions to this issue.

Microsoft Office cannot open this file because some parts are missing or invalid

You’ll receive the following full error message when this issue is triggered on your system;

Microsoft Word
We’re sorry. We can’t open Document because we found a problem with Its contents.
Microsoft Office cannot open this file because some parts are missing or invalid.

If you have encountered the Microsoft Office cannot open this file because some parts are missing or invalid error message on your Windows 11/10 computer when opening a Microsoft Office document, you can try our recommended solutions below in no particular order and see if that helps you resolve the issue on your system.

  1. Check Task Manager
  2. Run AV scan on the Word document
  3. Open the Word document in Safe Mode
  4. Repair and Recover the corrupted Word document

Let’s take a look at the description of the process involved concerning each of the listed solutions

1] Check Task Manager

Among other reasons for the issue, the error can occur when you attempt to access a document written in a previous version of Microsoft Office, such as 2007 or 2003. Some affected users reported that what worked for them in resolving the Microsoft Office cannot open this file because some parts are missing or invalid error on their Windows 11/10 computer was simply open Task Manager, switch to the Processes tab and end task for any WINWORD.EXE process. Once done, re-opened the problematic Word document – the document opened throwing the error prompt but with the repaired file. The final step was to exit the error prompt and click on the repaired file that appeared to the left side of the screen and then saved the file to another location on the local drive.

2] Run AV scan on the Word document

Run AV scan on the Word document

A corrupted Microsoft Office document could due virus/malware infection. So, you can scan the document using Microsoft Defender or any reputable third-party antivirus software to check if the file is malicious or not. Once the scan completes, see if the document can be opened now with all the contents intact. If so, then as a necessary precaution, you should run a full system AV scan.

3] Open the Word document in Safe Mode

Open Word document in Safe Mode

A rogue addon or resource can potentially damage or corrupt your Word document. To rule out this possibility as a potential culprit, especially if you have recently installed an addon, you can open Word in Safe Mode and see if the problem you’re currently facing is resolved. If the issue is fixed, then you need to uninstall any addon you installed recently. But, if the issue persists, you can try the next solution.

4] Repair and Recover the corrupted Word document

Repair and Recover the corrupted Word document

This solution requires you to Repair and Recover the corrupted Word document. But, keep in mind that you may not be able to recover the document if the type of file corruption suggests that it was opened in Word when it was located on a USB Drive, or saved from Word directly to an external USB drive.

It’s best practice not to work with Word or any Office documents when they are located on a USB drive or save from Word directly to such a drive; doing so could cause catastrophic, unrecoverable corruption of the document. To forestall future occurrences whereby you may lose important documents, we recommend you always save a copy of your document to OneDrive.

Hope this post helps you!

Related:

  • Word cannot open this file because it is larger than 512 Megabytes
  • Word cannot open the file because the file format does not match the file extension
  • Microsoft Office cannot open this file because the .zip archive file is an unsupported version
  • Microsoft Office cannot open this file because there are problems with the contents.

How do I fix an invalid Word document?

To fix an invalid Word document on your Windows 11/10 PC, follow these steps to repair Word file by Repair option:

  • Launch the Microsoft Word app in your system.
  • Go to the file option and click to Open.
  • Choose the damaged Word file and select the file.
  • In below, click to the down arrow on the Open button.
  • Here select Open and Repair option to repair Word files.

How do you fix the File is corrupted and cannot be opened Word?

To fix The file is corrupt and cannot be opened in Word, Excel, PowerPoint, you can try this suggestion:

  • Launch the Office document on your computer.
  • Head to the Files menu.
  • Open the Trust Center > Trust Center settings.
  • Click on Protected View.
  • Now, uncheck all the checkboxes in the tab.
  • Click OK and restart the Office.

Why is Word not letting me open a document?

There could be a number of reasons why Word isn’t opening a document on your computer. If Microsoft Word won’t open you can try repairing the Office installation. You can select the option Quick Repair or Online Repair to repair your Office programs.

Ezoic

Obinna Onwusobalu has studied Information & Communication Technology and is a keen follower of the Windows ecosystem. He has been a Windows Insider MVP (2020). He runs a computer software clinic.

Question

Issue: How to Recover Microsoft Word Documents?

Hello. I need someone to help recover my Word file ASAP. At the moment, I’m struggling with my BA thesis, which has to be done this Friday. A half of an hour my PC crashed due to the electricity problems and the worst thing is that the word document with BA was opened. Now I can’t open it due to the “Microsoft Office cannot open this file because some parts are missing or invalid” error. For some unknown reason, autosave was disabled, and I did not know that!!! I did not touch anything after that because I’m afraid to lose my work. Could you please help to recover the file?

Solved Answer

Microsoft Word remains one of the most popular applications for word processing.[1] However, there is a possibility of issues with the program still. “Microsoft Office cannot open this file because some parts are missing or invalid” message may be caused by corrupted or some issues that occurred during the saving of your file.

If a computer loses power or crashes as the program is writing to the disk there is a high possibility of files crashing. When the part of a file is left behind, the document becomes corrupted and cannot be opened properly. Other file corruptions, storage media issues, and even computer viruses can cause these issues with files.

The recent version of Microsoft Word has a function that allows minimizing corruption of the files. By AutoSaving the document to a different location instead of saving on top of the current existing file. The nature of this file corruption should dictate how to recover the document, so there are many solutions depending on the reason. Make sure to try all the methods listed below.

Recovering Microsoft Word filesThere are many reasons why Word files get corrupted and different errors occur on the screen as well as solutions for the issue.

The culprit of corruption may be a virus infection or the system’s crash/power loss. The latter variant is most frequent and may lead to errors like the following:

The file is corrupt and cannot be opened.

or

Microsoft Office cannot open this file because some parts are missing or invalid.

That could mean that the Word document got corrupted due to improper saving or closing. There are other data corruption causes, but in most of the cases, it is possible to recover the file or at least to minimize the loss. Unfortunately, if your PC forcefully shut down due to the power loss, it might have been curtailed and hard to recover. Nevertheless, if you can’t open a Word file and need it desperately, you can always try the following MS Word file recovery methods.

Methods to recover Microsoft Word files



Recover now!




Recover now!

To recover needed system components, please, purchase the licensed version of Reimage Reimage recovery tool.

Various issues with Windows versions and updates can cause bugs or issues with the system, errors, and corruption of the files.[2] Fortunately, Windows got several updates and fixes, patches to ensure the end of these issues. The same thing may happen to MS Word too. Maybe your program is affected or some settings need renewal.

In case your PC has been infected with a virus, for example, the one that encrypts files, you will have to remove the virus first and then try to decrypt the damaged Word file.[3] First of all, remove the virus with a professional anti-malware, say ReimageMac Washing Machine X9. After that, check this article to find data recovery methods.

Method 1. Use Microsoft Word Repair tool



Recover now!




Recover now!

To recover needed system components, please, purchase the licensed version of Reimage Reimage recovery tool.

Microsoft Word Repair is an inbuilt tool, which can be launched by following these steps:

  1. Start Microsoft Word.
  2. Open File and select Open.
  3. Find the file that has been corrupted and click it.
  4. Click the Open button and select Open and Repair.

    Open and repair the documentYou can use this automatic Word repair function by opening the needed file.

Method 2. Recover text only



Recover now!




Recover now!

To recover needed system components, please, purchase the licensed version of Reimage Reimage recovery tool.

If you cannot recover everything from the corrupted document, at least, try to restore text. Although you will lose images and formatting, a long and important text recovery would minimize the loss to the minimum:

  1. Launch Microsoft Word.
  2. Open File and select Open.
  3. Find the file that has been corrupted and click it.
  4. Select All Files and click on Recover Text From Any File option from the drop-down menu.

    Recover textThere is an option of recovering text from any file.

  5. Click Open and save the file to the new location.

Method 3. Use Notepad to save text



Recover now!




Recover now!

To recover needed system components, please, purchase the licensed version of Reimage Reimage recovery tool.

This method will help you to recover the text only. Although that’s not the best solution, it’s better to recover at least something than nothing, isn’t it?

  1. Find the Word document you cannot open.
  2. Right-click on it and select Open with.
  3. Click Choose default program and select Other Programs.
  4. Pick out Notepad and uncheck the Always use the selected program to open this kind of file box.

    Change some settings to your MS wordMake sure that the MS word program is always used to open this kind of files.

  5. Click OK to save the option and check if the text from the corrupted Word document has successfully been transferred to Notepad.
  6. If it’s there, copy the text and paste it into a new word document.

Method 4. Install a third-party tool



Recover now!




Recover now!

To recover needed system components, please, purchase the licensed version of Reimage Reimage recovery tool.

Check the Internet for recovery tools that can recover corrupted Word files. Before downloading it, make a research on it and make sure to download it from a reliable source.

Recover files and other system components automatically

To recover your files and other system components, you can use free guides by ugetfix.com experts. However, if you feel that you are not experienced enough to implement the whole recovery process yourself, we recommend using recovery solutions listed below. We have tested each of these programs and their effectiveness for you, so all you need to do is to let these tools do all the work.

Reimage — a patented specialized Windows repair program. It will diagnose your damaged PC. It will scan all System Files, DLLs and Registry Keys that have been damaged by security threats.Reimage — a patented specialized Mac OS X repair program. It will diagnose your damaged computer. It will scan all System Files and Registry Keys that have been damaged by security threats.
This patented repair process uses a database of 25 million components that can replace any damaged or missing file on user’s computer.
To repair damaged system, you have to purchase the licensed version of Reimage malware removal tool.

Press mentions on Reimage

To stay completely anonymous and prevent the ISP and the government from spying on you, you should employ Private Internet Access VPN. It will allow you to connect to the internet while being completely anonymous by encrypting all information, prevent trackers, ads, as well as malicious content. Most importantly, you will stop the illegal surveillance activities that NSA and other governmental institutions are performing behind your back.

Unforeseen circumstances can happen at any time while using the computer: it can turn off due to a power cut, a Blue Screen of Death (BSoD) can occur, or random Windows updates can the machine when you went away for a few minutes. As a result, your schoolwork, important documents, and other data might be lost. To recover lost files, you can use Data Recovery Pro – it searches through copies of files that are still available on your hard drive and retrieves them quickly.

Hi ACG_JC,

Thank you for posting and we are glad to help with you.

Have you resolved your issue yet? After reading your post, I tested with you code and also encountered the same issue.

What’s the version of your office? I use Office2010. I have spent a lot of time to research your issue, but I haven’t fixed your issue. I think it may be related with the wrong content of the xml file or the namespace. I succeeded in generating
word2010 document with the following code. It is not the same with your code, but I think it may help you:

Imports DocumentFormat.OpenXml
Imports System.Xml
Imports System.Text
Imports System.IO
Imports System.IO.Packaging
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles Button1.Click
        Dim filepath As String
        filepath = AppDomain.CurrentDomain.BaseDirectory & Guid.NewGuid.ToString() & ".docx"
        CreateXMLDocument(filepath)
    End Sub

    Public Sub CreateXMLDocument(ByVal filepath As String)

        '-- Step 1 - Creating the document xml
        Dim _nameSpaceURI As String = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
        Dim doc As New XmlDocument()
        Dim _wWordDoc As XmlElement = doc.CreateElement("w:wordDocument", _nameSpaceURI)
        doc.AppendChild(_wWordDoc)
        Dim _wbody As XmlElement = doc.CreateElement("w:body", _nameSpaceURI)
        _wWordDoc.AppendChild(_wbody)

        For row As Integer = 0 To 1
            Dim _wp1 As XmlElement = doc.CreateElement("w:p", _nameSpaceURI)
            _wbody.AppendChild(_wp1)
            Dim _wr1 As XmlElement = doc.CreateElement("w:r", _nameSpaceURI)
            _wp1.AppendChild(_wr1)
            Dim _wt11 As XmlElement = doc.CreateElement("w:t", _nameSpaceURI)
            _wr1.AppendChild(_wt11)
            Dim _wt1 As XmlNode = doc.CreateNode(XmlNodeType.Text, "w:t", _nameSpaceURI)
            _wt1.Value = "Test"
            _wt11.AppendChild(_wt1)
        Next

        'Create Package
        Dim _Package As Package

        _Package = Package.Open(filepath, FileMode.Create, FileAccess.ReadWrite)

        Dim _uri As Uri

        _uri = New Uri("/word/document.xml"UriKind.Relative)

        Dim part As PackagePart
        ' part = _Package.CreatePart(_uri, "application/vnd.ms-word.main+xml")
        part = _Package.CreatePart(_uri, "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml")

        Dim partWrt As StreamWriter
        partWrt = New StreamWriter(part.GetStream(FileMode.Create, FileAccess.Write))
        doc.Save(partWrt)
        partWrt.Close()
        _Package.Flush()

        'Create Relationship
        _uri = New Uri("/word/document.xml"UriKind.Relative)
        Dim rel As PackageRelationship
        'rel = _Package.CreateRelationship(_uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "rId1")
        rel = _Package.CreateRelationship(_uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument""rId1")

        _Package.Flush()
        _Package.Close()
    End Sub

    'Private Function GetData() As DataView
    '    Dim dv As New DataView
    '    Dim dt As New DataTable
    '    Dim arr() As String = {"ID1", "UnitNum1", "RemarkNo1", "DrawingNumber1", "Drop1", "Elevation1", "Priority1", "StyleName1", "ProjectName1", "OrderNumber1"}
    '    dt.Columns.Add("ProjectID")
    '    dt.Columns.Add("UnitNumber")
    '    dt.Columns.Add("RemakeNo")
    '    dt.Columns.Add("DrawingNumber")
    '    dt.Columns.Add("Drop")
    '    dt.Columns.Add("Elevation")
    '    dt.Columns.Add("Priority")
    '    dt.Columns.Add("StyleName")
    '    dt.Columns.Add("ProjectName")
    '    dt.Columns.Add("OrderNumber")

    '    dt.Rows.Add(arr)
    '    dt.Rows.Add(arr)
    '    Return dt.DefaultView
    'End Function
End Class

Could it be the reason of openxml namespace? The Office2010 namespace seems to be different with Office2007. I can only give you such directions. I hope it can help you and feel free to follow up after you have researched.

Best Regards,


Bruce Song [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Marked as answer by

    Tuesday, February 8, 2011 9:17 AM

  • Remove From My Forums
  • Question

  • Hi,

    I have created a word document in Sharepoint 2010 Document Library by using visual studio 2010 (webpart) and OPenXml. The Document is created in the Document Library, but while I tried open it, showing an error that «Microsoft Office cannot open this
    file because some parts are missing or Invalid»

    The code I used is 

    public void CreateDocument(string docName)
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    using (WordprocessingDocument doc = WordprocessingDocument.Create(memStream, WordprocessingDocumentType.Document))
                    {
                       
                        doc.AddMainDocumentPart();
                        
                        doc.MainDocumentPart.Document =
                        new Document(
                        new Body(
                        new Paragraph(
                        new Run(
                        new Text("Its a new Document!")))));
                       
                        doc.MainDocumentPart.Document.Save();
                        
                        AddToSharePoint(memStream,docName);
    
                    }
                }
            }
            protected void AddToSharePoint(MemoryStream memStream, string fileName)
            {
                string siteUrl = SPContext.Current.Site.ToString();
                Label1.Text = siteUrl;
                using (SPSite spSite = new SPSite(siteUrl))
                {
                    
                    SPList docLib = spSite.RootWeb.Lists["Candidate Documents"];
                    SPFile file = docLib.RootFolder.Files.Add(fileName, memStream, true);
                    file.Update();
                }
            }

    Pls Help me to find out the solution.

    Thanks In Advance 

    Regards

    Mine


    Mrs . Sola Rajesh Corporate Trainer — Microsoft Technologies

Answers

  • Here is working code, validated this against my 2013 instance:

    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml.Wordprocessing;
    using Microsoft.SharePoint;
    using System.IO;
    
    namespace WordXml
    {
        class Program
        {
            static void Main(string[] args)
            {
                CreateDocument("Test.docx");
            }
    
            public static void CreateDocument(string docName)
            {
                using (Stream memStream = new MemoryStream())
                {
                    using (WordprocessingDocument doc = WordprocessingDocument.Create(memStream, WordprocessingDocumentType.Document))
                    {
                        var mainPart = doc.AddMainDocumentPart();
                        mainPart.Document = new Document();
                        var body = mainPart.Document.AppendChild(new Body());
                        var paragraph = body.AppendChild(new Paragraph());
                        var run = paragraph.AppendChild(new Run());
                        run.AppendChild(new Text("Testing document..."));
                    }
                    AddToSharePoint(memStream, docName);
                }
            }
            protected static void AddToSharePoint(Stream memStream, string fileName)
            {
                var siteUrl = "http://spwebapp1";
                using (SPSite spSite = new SPSite(siteUrl))
                {
    
                    SPList docLib = spSite.RootWeb.Lists["Documents"];
                    SPFile file = docLib.RootFolder.Files.Add(fileName, memStream, true);
                    file.Update();
                }
            }
        }
    }
    


    Trevor Seward, MCC

    Follow or contact me at…
      



    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    • Marked as answer by

      Tuesday, December 10, 2013 10:05 AM

Понравилась статья? Поделить с друзьями:
  • Microsoft office 2016 сбой активации продукта как исправить
  • Microsoft office 2013 сбой активации продукта как исправить
  • Microsoft office 2013 error code 0 1011
  • Microsoft office 2007 ошибка при направлении команды приложению
  • Microsoft odbc driver manager function sequence error