none
Issue about attach document to project task RRS feed

  • Question

  • Hi

    I met a bug in project server 2007 recently.First I upload a document to a customized project workspace folder,then attach the document to a task by psi ,it execute no error. After that I go to the project details in pwa ,I can see the document link in the list ,but when I click the link it displays error "Object reference not set to an instance of an object",I want to know if it is the pwa problem or my code problem.The following is the method of attaching document to task.

     

    /// <summary>
    /// Add link to task
    /// </summary>
    /// <param name="list">SPList</param>
    /// <param name="docid">Document id</param>
    /// <param name="taskUid">TaskUID</param>
    /// <param name="projectUid">ProjectUID</param>

    public void Related(SPList list, int docid, Guid taskUid, Guid projectUid)
            {

                private PSLibrary.WebObjectType webObjectType;

                #region add link
                CookieContainer cookies = new CookieContainer();
                //writelogs.recordLog(taskUid.ToString());


                WebSvcObjectLinkProvider.ObjectLinkProvider objectLinkProvider =
                    new WebSvcObjectLinkProvider.ObjectLinkProvider();

                objectLinkProvider.Url = Configs.pwaurl + "/_vti_bin/PSI/ObjectLinkProvider.asmx";
                //objectLinkProvider.Credentials = new System.Net.NetworkCredential(Configs.PSIAdminName, Configs.PSIAdminPWD, Configs.PSIDomin);
                objectLinkProvider.Credentials = CredentialCache.DefaultCredentials;
                objectLinkProvider.CookieContainer = cookies;

                SPListItem item = list.GetItemById(docid);
                int itemTPID = item.ID;
                Guid listGuid = list.ID;

                Guid taskWebObjectUid = Guid.Empty;

                string listName = list.Title.ToString();
                //writelogs.recordLog(listName);

                WebSvcObjectLinkProvider.ObjectLinkProviderDataSet dsLinkedObjects =
     objectLinkProvider.ReadTaskWebObject(taskUid);


                //dsLinkedObjects = olpClient.ReadTaskWebObject(taskUid);

                int numTaskWebObjects = dsLinkedObjects.WebObjects.Count;

                if (numTaskWebObjects > 0)
                    taskWebObjectUid = dsLinkedObjects.WebObjects[0].WOBJ_UID;

     


                WebSvcObjectLinkProvider.ObjectLinkProviderDataSet dsTask =
    new WebSvcObjectLinkProvider.ObjectLinkProviderDataSet();
                WebSvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow taskRow =
                    dsTask.WebObjects.NewWebObjectsRow();


                //writelogs.recordLog("222222");
                // Provide information to the Web object row for the task. 
                // If a task web object does not exist, AddWebObjects creates
                // a new web object and updates WOBJ_UID in taskRow. 
                taskRow.WOBJ_UID = taskWebObjectUid;
                taskRow.WOBJ_TASK_UID = taskUid;
                taskRow.WOBJ_PROJ_UID = projectUid;
                taskRow.WOBJ_TYPE = (int)PSLibrary.WebObjectDatabaseType.Task;
                dsTask.WebObjects.AddWebObjectsRow(taskRow);

                // Create a web object for the list item, with the TP_ID of the list item.
                //Response.Write("Creating a web object for the list item...");

                WebSvcObjectLinkProvider.ObjectLinkProviderDataSet dsListItems =
    new WebSvcObjectLinkProvider.ObjectLinkProviderDataSet();
                WebSvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow listItemRow =
                    dsListItems.WebObjects.NewWebObjectsRow();
                //writelogs.recordLog("33333333");

                // Provide information to the web object row for the list item. 
                // If a list item web object does not exist, AddWebObjects creates
                // a new web object and updates WOBJ_UID in listItemRow. 
                listItemRow.WOBJ_UID = Guid.NewGuid();
                listItemRow.WOBJ_TP_ID = itemTPID;
                listItemRow.WOBJ_LIST_NAME = listGuid;
                listItemRow.WOBJ_PROJ_UID = projectUid;

                string linkedItems = "";

                switch (listName)
                {
                    
                    case "Issues":
                        listItemRow.WOBJ_TYPE =
                            (int)PSLibrary.WebObjectDatabaseType.Issue;
                        webObjectType = PSLibrary.WebObjectType.Issue;
                        linkedItems = "\nIssues found for task: " + taskUid.ToString();
                        break;
                    case "Risks":
                        listItemRow.WOBJ_TYPE =
                            (int)PSLibrary.WebObjectDatabaseType.Risk;
                        webObjectType = PSLibrary.WebObjectType.Risk;
                        linkedItems = "\nRisks found for task: " + taskUid.ToString();
                        break;
                    case "Documents":
      //my customized folder
                    case "outinputdoc":
                        listItemRow.WOBJ_TYPE =
                            (int)PSLibrary.WebObjectDatabaseType.Document;
                        webObjectType = PSLibrary.WebObjectType.Document;
                        linkedItems = "\nDocuments found for task: " + taskUid.ToString();
                        break;
                    case "Commitments":  // Commitments are now called Deliverables.
                        listItemRow.WOBJ_TYPE =
                            (int)PSLibrary.WebObjectDatabaseType.Commitment;
                        webObjectType = PSLibrary.WebObjectType.Commitment;
                        linkedItems = "\nDeliverables found for task: " + taskUid.ToString();
                        break;
                    default:
                        string errMess = "\n" + listName +
                            " is not a default SharePoint list type for task links.";
                        //Response.Write(errMess);
                        break;
                }
                dsListItems.WebObjects.AddWebObjectsRow(listItemRow);
                //writelogs.recordLog("44444444");
                // You can link the task to multiple list items by adding multiple rows 
                // to dsListItems and adding ObjectLinkType values to the array of link types.
                WebSvcObjectLinkProvider.WebObjectLinkType generalLinkType = WebSvcObjectLinkProvider.WebObjectLinkType.General;
                WebSvcObjectLinkProvider.WebObjectLinkType[] wssLinkTypeArray = { generalLinkType };

                //writelogs.recordLog("5555555");
                objectLinkProvider.CreateWebObjectLinks(dsTask, dsListItems, wssLinkTypeArray);
                //writelogs.recordLog("6666666");
                #endregion
            }

    If anyone have any idea?

     

     

    Friday, May 3, 2013 5:55 AM