SharePoint Project import (mpp File Import ),
Sharepoint Study Notes
Http://blog.csdn.net/qq873113580/article/details/20390149
Note: Microsoft Project Basic components may not be automatically registered on different computers in earlier versions, so you can download the latest version.
1. Install Microsoft project software. I installed 2010.
2. Test on Net.
3. This error occurs when the code is transplanted to Sharepoint.
Failed to retrieve components whose CLSID is {36D27C48-A1E8-11D3-BA55-00C04F72F325} in the COM factory because of the following error: 80010001 the caller refused to receive the call. (The exception is from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED )).
4. Various Baidu searches and online information may be related to account Permissions
5. The following information is found online.
-Enter dcomcnfg in the command line and the "component service" Manager is displayed.
-Choose component service> Computer> my computer> DCOM configuration. Right-click Microsoft Project and choose Properties"
-In the "properties" dialog box, click the "ID" tab and select "Interactive User ""
-Then find "security", select Custom permissions for all the following permissions, and add all permissions for various users. ErverOne, admin, Net... I randomly added permissions for many roles.
6. After the above layout, everyone else said OK, and I tried it myself or not. I was wondering if it was a code problem. Check N and then compare the Code with the Net version.
7. Finally, I found a permission escalation code in sharepoint.
SPSecurity. RunWithElevatedPrivileges (delegate
{
// Write the code here
Microsoft. Office. Interop. MSProject. ApplicationClass prj = new Microsoft. Office. Interop. MSProject. ApplicationClass (); // This Code directly reports an error
});
8. It is estimated that the account permission in sharepoint is not recognized in the permission, So I extracted the new Code and changed it to this way.
Microsoft. Office. Interop. MSProject. ApplicationClass prj = new Microsoft. Office. Interop. MSProject. ApplicationClass (); //
SPSecurity. RunWithElevatedPrivileges (delegate
{
// Write the code here
});
9. The following is a small example of how to use Project import to obtain data.
// Program object
Microsoft. Office. Interop. MSProject. ApplicationClass prj = new Microsoft. Office. Interop. MSProject. ApplicationClass ();
// File path
String prjFileName = "xxx. mpp ";
// Read the file. You only need to change the prjFileName value. The default value of the following parameter is enough.
Prj. fileOpen (prjFileName, true, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing, Type. missing, Microsoft. office. interop. MSProject. pjPoolOpen. pjPoolReadOnly, Type. missing, Type. missing, Type. missing, Type. missing );
Foreach (Microsoft. Office. Interop. MSProject. Project proj in prj. Projects)
{
Foreach (Microsoft. Office. Interop. MSProject. Task task in proj. Tasks)
{
// Task is the required object. task. Attribute names cannot be changed here. They are all defined by the system.
If (task! = Null)
{
// The level of the task. OutlineLevel tree structure. The default value starts from 1. Check the attribute names themselves for what many system definitions represent. I will not use the Project to do things, so I will not say much about it.
// Task. Text1. ...... task. Text30 is used for custom columns and is also provided by the system.
}
}
Break; // here, break is added. In fact, I did not go into the details of the prj. Projects. Currently, only one Project file is used, so you can find one file directly during the loop.
}