/// <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;
            }
        }
        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);
        }
Beispiel #3
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));
        }