Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am doing outlook 2007 vsto programming with SharePoint Server 2007.

Now problem is that as I am calling getListItemAsync asynchronously so the GetListItemItem completed event is not firing.So the ListItemCompleted method is not being executed.

I have changed the code getlistitemasync to getlistitem but as getlistitemcomepleted event is not being executed so listitemcompleted method is not being executed and therefore I can not update the gridview of the user control of the custom taskpane.

I need to run this code syncronously.do you have any solution so that I can register the list service's getlistItemCompletedEvent?

This is my code which is running in BackGroundWorker's doWork event.

private void GetListItemsAsyncWrapper(string m_uploadDocLibraryName, string viewname, XmlNode ndQuery, XmlNode ndViewFields, string rowlimit, XmlNode ndQueryOptions, string webid, object uploadData, CommonProperties property)
{
    try
    {

    // for 2007//
    ListWebService.Lists listService = new ListWebService.Lists();
    listService.Credentials = property.Credentionals;
    listService.Url = property.CopyServiceURL;
    listService.GetListItemsCompleted += new ListWebService.GetListItemsCompletedEventHandler(listService_GetListItemsCompleted);
    // listService.GetListItemsAsync(m_uploadDocLibraryName, null, ndQuery, ndViewFields, "2", ndQueryOptions, null, uploadData);

    XmlNode n = listService.GetListCollection();


    string urlroot = property.LibSite.Remove(property.LibSite.Length - 1);
    foreach (XmlNode item in n.ChildNodes)
    {
        string strcompare = urlroot + item.Attributes["DefaultViewUrl"].Value;
        if (strcompare == property.CompletedoclibraryURL)
        {
            m_uploadDocLibraryName = item.Attributes["Title"].Value;
            cmproperties.UploadDocLibraryName = m_uploadDocLibraryName;
            break;

        }

    }

    listService.GetListItemsAsync(m_uploadDocLibraryName, null, ndQuery, ndViewFields, "2", ndQueryOptions, null, uploadData);
    //listService.GetListItems(m_uploadDocLibraryName, null, ndQuery, ndViewFields, "2", ndQueryOptions, null);
    UploadItemsData senduploadData = (UserModule.UploadItemsData)uploadData;
                }
catch (Exception ex)
{
}

}


/// <summary>
/// <c>listService_GetListItemsCompleted</c> event handler
/// calls <c>ListItemCompleted</c> method
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void listService_GetListItemsCompleted(object sender, SharePoint_Link07.ListWebService.GetListItemsCompletedEventArgs e)
{

try
{
    XmlNode xmlnode = e.Result;
    UploadItemsData uploaditemdata = (UploadItemsData)e.UserState;
    ListItemCompleted(xmlnode, uploaditemdata);

}
catch (Exception ex)
{
    m_isUploadingCompleted = true;
    DelegateUpdateGridRow pdSteps = new DelegateUpdateGridRow(UpdataGridRows);
    this.Invoke(pdSteps, new object[] { false, "uploaded with error", "", null });

    EncodingAndDecoding.ShowMessageBox("Error occured, may be th document Library does not exists", "Error occured, may be th document Library does not exists", MessageBoxIcon.Error);
}


}

/// <summary>
/// <c>ListItemCompleted</c> function
/// gets uploaded file  url and calls <c>UpdataGridRows</c> method to  add new row in grid.
/// </summary>
/// <param name="ndvolListItem"></param>
/// <param name="uitemdata"></param>
public void ListItemCompleted(XmlNode ndvolListItem, UploadItemsData uitemdata)
{
try
{


    XmlNode ndVolunteerListItems = ndvolListItem;
    string test = uitemdata.UploadFileName;
    if (ndVolunteerListItems != null)
    {

        if (ndVolunteerListItems.ChildNodes.Count == 3)
        {

            if (ndVolunteerListItems.ChildNodes[1].ChildNodes.Count > 1)
            {
                string id = Convert.ToString(ndVolunteerListItems.ChildNodes[1].ChildNodes[1].Attributes["ows_ID"].Value);
                //////////

                UpdateItemAttributes(id, uitemdata);

                //////////

                string sucessURL1 = m_LibSite + m_uploadFolderNode.ChildNodes[3].InnerText + "/Forms/EditForm.aspx?ID=" + id + "&UpFName=" + uitemdata.UploadFileName; ;
                m_isUploadingCompleted = true;
                UpdataGridRows(true, "Success", sucessURL1, uitemdata);

                UploadItemsData item = uitemdata; //(UploadItemsData)e.UserState;


                //try
                //{
                //    string fileCheckin = m_sharepointLibraryURL.Substring(0, m_sharepointLibraryURL.LastIndexOf("Forms")) + item.UploadFileName;
                //    bool b = listService.CheckInFile(fileCheckin, "Uplaod Completed.", "1");
                //}
                //catch (Exception ex)
                //{ 
                //}
            }
        }
    }
}
catch (Exception ex)
{
    string outMessage1 = ex.Message;
    if (ex.InnerException != null)
    {
        outMessage1 = ex.InnerException.Message;
    }
    m_isUploadingCompleted = true;
    DelegateUpdateGridRow pdSteps = new DelegateUpdateGridRow(UpdataGridRows);
    this.Invoke(pdSteps, new object[] { false, "Exception in GetListItemsCompleted Event." + outMessage1, " ", uitemdata });
}
}
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.