/// <summary>
        /// This method first connects to the Organization service. Afterwards,
        /// retrieves the absolute URL and the parent site collection URL of a
        /// SharePoint document location record.
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
        {
            try
            {
                // Connect to the Organization service.
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri, serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    CreateRequiredRecords();
                    // Retrieve the absolute URL and the Site Collection URL
                    // of the SharePoint document location record.
                    RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
                    {
                        Target = new EntityReference(SharePointDocumentLocation.EntityLogicalName, _spDocLocId)
                    };
                    RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)_serviceProxy.Execute(retrieveRequest);

                    Console.WriteLine("Absolute URL of document location record is '{0}'.", retriveResponse.AbsoluteUrl.ToString());
                    Console.WriteLine("Site Collection URL of document location record is '{0}'.", retriveResponse.SiteCollectionUrl.ToString());
                    DeleteRequiredRecords(promptforDelete);
                }
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parentEntityGuid"></param>
        /// <returns></returns>
        public string GetSharePointDocLocAbsoluteUrlFromParentRecord(string parentEntityGuid)
        {
            var sharePointDocLocQuery = new QueryExpression("sharepointdocumentlocation")
            {
                ColumnSet = new ColumnSet("sharepointdocumentlocationid")
            };

            sharePointDocLocQuery.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, Guid.Parse(parentEntityGuid));
            sharePointDocLocQuery.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);

            var docLocs = _service.RetrieveMultiple(sharePointDocLocQuery);

            if (docLocs.Entities.Count == 0)
            {
                return(null);
            }

            var docLoc = docLocs[0].ToEntityReference();

            var urlRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
            {
                Target = docLoc
            };
            var urlResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)_service.Execute(urlRequest);

            return(urlResponse.AbsoluteUrl.ToString());
        }
        private void RetrieveUrlById(Guid id)
        {
            var sourceUrlRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
            {
                Target = new EntityReference("sharepointdocumentlocation", id)
            };
            var sourceUrlResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)CrmContext.OrganizationProxy.Execute(sourceUrlRequest);

            WriteObject(sourceUrlResponse);
        }
        private static string GetAbsoluteURLFromLocation(Common objCommon, EntityCollection locatioColl)
        {
            string absoluteURL;

            if (locatioColl.Entities.Count > 0)
            {
                RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
                {
                    Target = new EntityReference(locatioColl[0].LogicalName, locatioColl[0].Id)
                };
                RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)objCommon.service.Execute(retrieveRequest);

                absoluteURL = retriveResponse.AbsoluteUrl.ToString();
                objCommon.tracingService.Trace("Absolute URL of document location record is '{0}'." + retriveResponse.AbsoluteUrl.ToString());
            }
            else
            {
                absoluteURL = "URL Not found";
            }

            return(absoluteURL);
        }
        /// <summary>
        /// This method first connects to the Organization service. Afterwards,
        /// retrieves the absolute URL and the parent site collection URL of a 
        /// SharePoint document location record.
        /// </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptforDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete)
        {
            try
            {
                //<snippetRetrieveAbsoluteAndSiteCollectionURLs1>
                // Connect to the Organization service. 
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    CreateRequiredRecords();
                    //<snippetRetrieveAbsoluteAndSiteCollectionURLs2>
                    // Retrieve the absolute URL and the Site Collection URL
                    // of the SharePoint document location record.
                    RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
                    {
                        Target = new EntityReference(SharePointDocumentLocation.EntityLogicalName, _spDocLocId)
                    };
                    RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)_serviceProxy.Execute(retrieveRequest);

                    Console.WriteLine("Absolute URL of document location record is '{0}'.", retriveResponse.AbsoluteUrl.ToString());
                    Console.WriteLine("Site Collection URL of document location record is '{0}'.", retriveResponse.SiteCollectionUrl.ToString());
                    //</snippetRetrieveAbsoluteAndSiteCollectionURLs2>
                    DeleteRequiredRecords(promptforDelete);
                }
                //</snippetRetrieveAbsoluteAndSiteCollectionURLs1>
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
示例#6
0
        public ActionResult Documents(string caseID)
        {
            if (null == caseID)
            {
                return(HttpNotFound());
            }

            string tekst = null;
            //string fileName = null;

            DocumentViewModel docsList = new DocumentViewModel();

            var url = context.SharePointDocumentLocationSet.Where(c => c.RegardingObjectId.Id == new Guid(caseID));

            if (url != null)
            {
                foreach (SharePointDocumentLocation b in url)
                {
                    tekst = b.RelativeUrl.ToString();

                    RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
                    {
                        Target = new EntityReference(SharePointDocumentLocation.EntityLogicalName, b.Id)
                    };

                    RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse =
                        (RetrieveAbsoluteAndSiteCollectionUrlResponse)context.Execute(retrieveRequest);
                }

                var targetSite = new Uri("https://adversum.sharepoint.com");
                var login      = ConfigurationManager.AppSettings["userName"];
                var password   = ConfigurationManager.AppSettings["password"];

                var securePassword = new SecureString();

                foreach (char c in password)
                {
                    securePassword.AppendChar(c);
                }

                var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);

                using (ClientContext clientContext = new ClientContext(targetSite))
                {
                    clientContext.Credentials = onlineCredentials;

                    if (tekst != null)
                    {
                        string path   = tekst + "/incident/" + tekst.ToString() + "/Klient";
                        Folder folder = clientContext.Web.GetFolderByServerRelativeUrl("/incident/" + tekst.ToString() + "/Klient");

                        FileCollection files = folder.Files;

                        clientContext.Load(folder);
                        clientContext.Load(files);



                        try
                        {
                            clientContext.ExecuteQuery();

                            int temp = 1;



                            foreach (var file in files)
                            {
                                docsList.DocsList.Add(new DocumentsViewObject()
                                {
                                    CaseID   = caseID,
                                    FileName = file.Name,
                                    Url      = file.ServerRelativeUrl.ToString(),
                                    DateOf   = file.TimeLastModified.ToShortDateString()
                                });

                                #region example
                                //var cell = new TableCell();
                                //var row = new TableRow();
                                //if (temp == 1)
                                //{
                                //    cell.Font.Bold = true;
                                //    cell.Text = "Plik";
                                //    row.Cells.Add(cell);
                                //    cell = new TableCell();
                                //    cell.Font.Bold = true;
                                //    cell.Text = "Data dodania";
                                //    row.Cells.Add(cell);
                                //    casetable.Rows.Add(row);
                                //}
                                //row = new TableRow();
                                //cell = new TableCell();

                                //LinkButton myLabel = new LinkButton();
                                //myLabel.Text = file.Name.ToString();
                                //myLabel.ID = "Label" + temp.ToString();
                                //myLabel.CommandArgument = file.ServerRelativeUrl.ToString();
                                //myLabel.Click += new EventHandler(Clicked);
                                //fileName = file.Name.ToString();
                                //panelukas.Controls.Add(myLabel);
                                //panelukas.Controls.Add(new LiteralControl("<br />"));

                                //cell.Controls.Add(myLabel);
                                //row.Cells.Add(cell);

                                //cell = new TableCell();
                                //cell.Text = file.TimeLastModified.ToShortDateString();
                                //row.Cells.Add(cell);
                                //casetable.Rows.Add(row);
                                #endregion example


                                temp++;
                            }
                            if (temp == 1)
                            {
                                ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
                            }
                        }
                        catch (Exception)
                        {
                            ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
                        }
                    }
                    else
                    {
                        ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
                    }
                }
            }
            else
            {
                ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
            }

            ViewBag.CaseID = caseID;

            return(View(docsList));
        }
示例#7
0
        public ActionResult Documents(string caseID)
        {
            if (null == caseID)
            {
                return HttpNotFound();
            }

            string tekst = null;
            //string fileName = null;

            DocumentViewModel docsList = new DocumentViewModel();

            var url = context.SharePointDocumentLocationSet.Where(c => c.RegardingObjectId.Id == new Guid(caseID));
            if (url != null)
            {

                foreach (SharePointDocumentLocation b in url)
                {
                    tekst = b.RelativeUrl.ToString();

                    RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
                    {
                        Target = new EntityReference(SharePointDocumentLocation.EntityLogicalName, b.Id)
                    };

                    RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse =
                        (RetrieveAbsoluteAndSiteCollectionUrlResponse)context.Execute(retrieveRequest);
                }

                var targetSite = new Uri("https://adversum.sharepoint.com");
                var login = ConfigurationManager.AppSettings["userName"];
                var password = ConfigurationManager.AppSettings["password"];

                var securePassword = new SecureString();

                foreach (char c in password)
                {
                    securePassword.AppendChar(c);
                }

                var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);

                using (ClientContext clientContext = new ClientContext(targetSite))
                {
                    clientContext.Credentials = onlineCredentials;

                    if (tekst != null)
                    {

                        string path = tekst + "/incident/" + tekst.ToString() + "/Klient";
                        Folder folder = clientContext.Web.GetFolderByServerRelativeUrl("/incident/" + tekst.ToString() + "/Klient");

                        FileCollection files = folder.Files;

                        clientContext.Load(folder);
                        clientContext.Load(files);

                        try
                        {

                            clientContext.ExecuteQuery();

                            int temp = 1;

                            foreach (var file in files)
                            {

                                docsList.DocsList.Add(new DocumentsViewObject()
                                {
                                    CaseID = caseID,
                                    FileName = file.Name,
                                    Url = file.ServerRelativeUrl.ToString(),
                                    DateOf = file.TimeLastModified.ToShortDateString()
                                });

                                #region example
                                //var cell = new TableCell();
                                //var row = new TableRow();
                                //if (temp == 1)
                                //{
                                //    cell.Font.Bold = true;
                                //    cell.Text = "Plik";
                                //    row.Cells.Add(cell);
                                //    cell = new TableCell();
                                //    cell.Font.Bold = true;
                                //    cell.Text = "Data dodania";
                                //    row.Cells.Add(cell);
                                //    casetable.Rows.Add(row);
                                //}
                                //row = new TableRow();
                                //cell = new TableCell();

                                //LinkButton myLabel = new LinkButton();
                                //myLabel.Text = file.Name.ToString();
                                //myLabel.ID = "Label" + temp.ToString();
                                //myLabel.CommandArgument = file.ServerRelativeUrl.ToString();
                                //myLabel.Click += new EventHandler(Clicked);
                                //fileName = file.Name.ToString();
                                //panelukas.Controls.Add(myLabel);
                                //panelukas.Controls.Add(new LiteralControl("<br />"));

                                //cell.Controls.Add(myLabel);
                                //row.Cells.Add(cell);

                                //cell = new TableCell();
                                //cell.Text = file.TimeLastModified.ToShortDateString();
                                //row.Cells.Add(cell);
                                //casetable.Rows.Add(row);
                                #endregion example

                                temp++;
                            }
                            if (temp == 1)
                            {

                                ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
                            }
                        }
                        catch (Exception)
                        {

                            ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
                        }
                    }
                    else
                    {

                        ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
                    }
                }
            }
            else
            {
                ViewBag.InfoDocs = "Brak dokumentów przypisanych do sprawy";
            }

            ViewBag.CaseID = caseID;

            return View(docsList);
        }