Esempio n. 1
0
 /// <summary>
 /// <c>copyws_CopyIntoItemsCompleted</c>  Event Handler 
 /// not currently used
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void copyws_CopyIntoItemsCompleted(object sender, SharePoint_Link.SPCopyService.CopyIntoItemsCompletedEventArgs e)
 {
 }
Esempio n. 2
0
        /// <summary>
        /// <c>getFileID_SecondAlternate</c> member function
        /// gets ID of the file uploaded to sharepoint document library when <c>getFileIDAlternate</c> member function  throw exception
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="cmproperty"></param>
        /// <param name="siteurl"></param>
        /// <param name="docLibrary"></param>
        /// <returns></returns>
        private static string getFileID_SecondAlternate(SharePoint_Link.UserModule.UploadItemsData udataitem, CommonProperties cmproperty, string siteurl, string docLibrary)
        {
            string result = string.Empty;

            try
            {

                Microsoft.SharePoint.Client.ClientContext ct = new ClientContext(siteurl);
                ct.Credentials = ListWebClass.GetCredential(cmproperty);
                result = UpdateAttributes(udataitem, result, ct, cmproperty, docLibrary);

                ct.Dispose();
            }
            catch (Exception)
            {

                result = getFileIDByIteration(udataitem, cmproperty, siteurl, docLibrary);

            }
            return result;
        }
Esempio n. 3
0
        /// <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_Link.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);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// <c>getFileIDByIteration</c> member function
        /// gets ID of the file uploaded to sharepoint document library when <c>getFileID_SecondAlternate</c> member function  throw exception
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="cmproperty"></param>
        /// <param name="siteurl"></param>
        /// <param name="docLibrary"></param>
        /// <returns></returns>
        private static string getFileIDByIteration(SharePoint_Link.UserModule.UploadItemsData udataitem, CommonProperties cmproperty, string siteurl, string docLibrary)
        {
            string result = string.Empty;
            Microsoft.SharePoint.Client.ClientContext ct = new ClientContext(siteurl);
            try
            {

                ct.Credentials = ListWebClass.GetCredential(cmproperty);
                Web oWeb = ct.Web;
                ct.Load(oWeb);
                ct.ExecuteQuery();
                ListCollection currentListCollection = oWeb.Lists;
                ct.Load(currentListCollection);
                ct.ExecuteQuery();
                int found = 0;

                foreach (List oList in currentListCollection)
                {

                    string one = docLibrary.Trim();
                    string two = oList.Title.Trim();
                    int indexofspace = -1;
                    indexofspace = one.IndexOf(' ');
                    while (indexofspace != -1)
                    {
                        one = one.Remove(indexofspace, 1);
                        indexofspace = one.IndexOf(' ');
                    }
                    indexofspace = two.IndexOf(' ');
                    while (indexofspace != -1)
                    {
                        two = two.Remove(indexofspace, 1);
                        indexofspace = two.IndexOf(' ');
                    }

                    if (one == two)
                    {
                        List list2 = ct.Web.Lists.GetByTitle(oList.Title);
                        result = UpdateAttributes(udataitem, result, ct, cmproperty, docLibrary);
                        //old removed
                        found += 1;
                    }

                    if (found > 0)
                    {
                        break;
                    }

                }
            }
            catch (Exception)
            {

                try
                {
                    result = UpdateAttributes(udataitem, result, ct, cmproperty, docLibrary);
                }
                catch
                { }
            }
            ct.Dispose();
            return result;
        }
Esempio n. 5
0
        /// <summary>
        /// <c>GetFileID</c> member function
        /// this member function is used to get ID of the file recently uploaded to sharepoint document library
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="cmproperty"></param>
        /// <param name="leftpart"></param>
        /// <returns></returns>
        private static string GetFileID(SharePoint_Link.UserModule.UploadItemsData udataitem, CommonProperties cmproperty, string leftpart)
        {
            string test = cmproperty.SharepointLibraryURL;
            string result = string.Empty;
            try
            {
                Microsoft.SharePoint.Client.ClientContext ct = new ClientContext(cmproperty.LibSite);
                ct.Credentials = ListWebClass.GetCredential(cmproperty);

                result = UpdateAttributes(udataitem, result, ct, cmproperty, cmproperty.UploadDocLibraryName);
                ct.Dispose();
            }
            catch (Exception ex)
            {
                try
                {

                    result = getFileIDByIteration(udataitem, cmproperty, cmproperty.LibSite, cmproperty.UploadDocLibraryName);

                    if (string.IsNullOrEmpty(result))
                    {
                        ////////////////
                        if (leftpart.StartsWith("/"))
                        {
                            leftpart = leftpart.Remove(0, 1);
                        }
                        string temurl = cmproperty.LibSite + leftpart;
                        result = getFileIDAlternate(udataitem, cmproperty, temurl);

                        ///////////////////
                        if (string.IsNullOrEmpty(result))
                        {
                            result = getFileID_SecondAlternate(udataitem, cmproperty, cmproperty.LibSite, leftpart + cmproperty.UploadDocLibraryName);
                        }
                        /////////////////

                        if (string.IsNullOrEmpty(result))
                        {
                            string p = leftpart;

                            string[] split = p.Split('/');
                            int len = split.Length;

                            for (int i = len - 1; i > 0; i--)
                            {

                                int ind = p.LastIndexOf(split[i].ToString());
                                if (ind != -1)
                                {

                                    p = p.Remove(ind);
                                    temurl = cmproperty.LibSite + p;

                                    result = getFileIDAlternate(udataitem, cmproperty, temurl);

                                    if (!string.IsNullOrEmpty(result))
                                    {
                                        break;
                                    }
                                }
                            }

                            if (string.IsNullOrEmpty(result))
                            {
                                for (int i = 1; i < len - 1; i++)
                                {

                                    int ind = p.LastIndexOf(split[i].ToString());
                                    if (ind != -1)
                                    {

                                        p = p.Remove(ind);
                                        temurl = cmproperty.LibSite + p;

                                        result = getFileID_SecondAlternate(udataitem, cmproperty, cmproperty.LibSite, p + cmproperty.UploadDocLibraryName); getFileIDAlternate(udataitem, cmproperty, temurl);

                                        if (!string.IsNullOrEmpty(result))
                                        {
                                            break;
                                        }
                                    }

                                }
                            }

                        }
                    }
                    //////////////////
                }
                catch (Exception)
                {

                }

            }

            return result;
        }
Esempio n. 6
0
        /// <summary>
        /// <c>uploadFilestoLibraryUsingClientOM</c> member function
        /// upload file to sharepoint Document Library using Client object model
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="cmproperty"></param>
        /// <returns></returns>
        public static bool uploadFilestoLibraryUsingClientOM(SharePoint_Link.UserModule.UploadItemsData udataitem, CommonProperties cmproperty)
        {
            bool result = false;
            try
            {

                CommonProperties cmproperties = new CommonProperties();
                string tempFilePath = UserLogManagerUtility.RootDirectory + "\\" + udataitem.UploadFileName;// +udataitem.UploadFileExtension;

                if (System.IO.File.Exists(tempFilePath))
                {
                    System.IO.File.Delete(tempFilePath);
                }

                FileStream fs = new FileStream(tempFilePath, FileMode.Create, FileAccess.ReadWrite);

                //////// out look storage//////////

                try
                {
                    if (udataitem.UploadType == TypeOfUploading.Mail)
                    {

                        Stream msgstream = new MemoryStream(cmproperty.FileBytes);

                        Utility.OutlookStorage.Message message = new OutlookStorage.Message(msgstream);
                        if (!string.IsNullOrEmpty(message.BodyText))
                        {
                            //  HashingClass.Hashedemailbody = HashingClass.ComputeHashWithoutSalt(message.BodyText, "MD5");

                        }
                        if (!string.IsNullOrEmpty(message.Subject))
                        {
                            HashingClass.Mailsubject = message.Subject;

                        }
                        if (message.SentDate != "")
                        {
                            HashingClass.Modifieddate = message.SentDate;

                        }

                    }
                }
                catch (Exception)
                {

                }

                //////////End of outlook storage////

                if (cmproperty.FileBytes != null)
                {

                    BinaryWriter bw = new BinaryWriter(fs);
                    bw.Write(cmproperty.FileBytes);
                    bw.Close();

                }

                ///updated new 6jan//////
                string strsitepath = cmproperty.LibSite;

                string strleftpart = "/";
                int firstindex = -1;
                int secondindex = -1;
                firstindex = strsitepath.IndexOf(@"//");
                try
                {

                    if (firstindex != -1)
                    {
                        if (strsitepath.Length >= (firstindex + 3))
                        {
                            secondindex = strsitepath.IndexOf(@"/", firstindex + 3);
                            if (secondindex != -1)
                            {
                                if (strsitepath.Length >= (secondindex + 1))
                                {
                                    strleftpart = strleftpart + strsitepath.Substring(secondindex + 1);
                                    if (strsitepath.Length > (secondindex + 1))
                                    {
                                        strsitepath = strsitepath.Remove(secondindex + 1);
                                    }

                                    cmproperty.LibSite = strsitepath;
                                }

                            }

                        }

                    }
                }
                catch (Exception)
                {
                }

                string pth = strleftpart + cmproperty.UploadDocLibraryName + "/" + udataitem.UploadFileName;

                // end of new///

                Microsoft.SharePoint.Client.ClientContext ct = new ClientContext(cmproperty.LibSite);

                ct.Credentials = ListWebClass.GetCredential(cmproperty);

                using (FileStream filestream = new FileStream(tempFilePath, FileMode.Open))
                {

                        Microsoft.SharePoint.Client.File.SaveBinaryDirect(ct, pth, filestream, true);

                };

                result = true;

                /////
                // Get ID of Uploaded File
                FileID = GetFileID(udataitem, cmproperty, strleftpart);
                HashingClass.Mailsubject = "";
                HashingClass.Modifieddate = "";
                HashingClass.Hashedemailbody = "";

                ////

                ////////////

                /////////////

                if (System.IO.File.Exists(tempFilePath))
                {
                    System.IO.File.Delete(tempFilePath);
                }

            }
            catch (Exception ex)
            {
                string errmessage = ex.Message.ToString();

                SharePoint_Link.frmUploadItemsList.UpLoadErrorMessage = errmessage;// ex.InnerException.Message.ToString();
                result = false;

            }

            return result;
        }
Esempio n. 7
0
        /// <summary>
        /// <c>listService_GetListItemsCompleted</c> Event Handler
        /// it gets the uploaded data node from sharepoint 2007 document library and calls 
        /// <c>listService_GetListItemsCompleted</c>  method to update status 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listService_GetListItemsCompleted(object sender, SharePoint_Link.ListWebService.GetListItemsCompletedEventArgs e)
        {
            try
            {
                if (e.Result != null)
                {
                    XmlNode ndVolunteerListItems = e.Result;
                    UserModule.UploadItemsData uploaditemdata = (UserModule.UploadItemsData)e.UserState;

                    SharePoint_Link.frmUploadItemsList fmuploaditemlist = new frmUploadItemsList();
                    fmuploaditemlist.ListItemCompleted(ndVolunteerListItems, uploaditemdata);

                }

            }
            catch (Exception ex)
            {

                string outMessage1 = ex.Message;
                if (ex.InnerException != null)
                {
                    outMessage1 = ex.InnerException.Message;
                }

                UserModule.UploadItemsData uitemdata = (UserModule.UploadItemsData)e.UserState;

                SharePoint_Link.frmUploadItemsList fmuploaditemlist = new frmUploadItemsList();
                fmuploaditemlist.UpdataGridRows(false, "exception in getlistitemscompleted event." + outMessage1, " ", uitemdata);

                fmuploaditemlist.Show();
                fmuploaditemlist.HideProgressPanel(true);

            }
        }
Esempio n. 8
0
        /// <summary> 
        /// <c>UpdateAttributes</c>   member function
        /// this member function updates metatags in sharepoint document library
        /// </summary>
        /// <param name="udataitem"></param>
        /// <param name="result"></param>
        /// <param name="ct"></param>
        /// <param name="cmproperty"></param>
        /// <param name="UploadDocLibraryName"></param>
        /// <returns></returns>
        private static string UpdateAttributes(SharePoint_Link.UserModule.UploadItemsData udataitem, string result, Microsoft.SharePoint.Client.ClientContext ct, CommonProperties cmproperty, string UploadDocLibraryName)
        {
            List list;
            string doclibtitle = UploadDocLibraryName;
            try
            {
                list = ct.Web.Lists.GetByTitle(UploadDocLibraryName);
                ct.Load(list); ct.ExecuteQuery();
            }
            catch (Exception ex)
            {
                ListCollection lc = ct.Web.Lists;
                ct.Load(lc); ct.ExecuteQuery();
                foreach (List item in lc)
                {
                    string siteurlroot = cmproperty.LibSite.Remove(cmproperty.LibSite.Length - 1);
                    string url = siteurlroot + item.DefaultViewUrl;
                    if (url == cmproperty.CompletedoclibraryURL)
                    {
                        doclibtitle = item.Title;
                        break;
                    }
                }

            }

            list = ct.Web.Lists.GetByTitle(doclibtitle);
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml =
            @"<View>
                <Query>
                  <Where>
                    <Eq>
                      <FieldRef Name='FileLeafRef' />
                      <Value Type='Text' >" + udataitem.UploadFileName + @" </Value>
                    </Eq>
                  </Where>
                </Query>
                <RowLimit>100</RowLimit>
              </View>";
            ListItemCollection listItems = list.GetItems(camlQuery);

            ct.Load(listItems);
            ct.ExecuteQuery();

            foreach (ListItem l in listItems)
            {
                result = l["ID"].ToString();

                try
                {

                    l["Title"] = HashingClass.Mailsubject;
                    l.Update();
                    ct.ExecuteQuery();

                    l["ModifiedDate"] = HashingClass.Modifieddate;

                    l.Update();
                    ct.ExecuteQuery();

                }
                catch (Exception ex)
                {

                }

            }
            return result;
        }