Category: Server-Side

A través de una aplicación de consola podemos crear items en una lista utilizando la librería cliente de SharePoint: string siteUrl = "https://mytenant.sharepoint.com/sites/mysite"; using (ClientContext clientContext = new ClientContext(siteUrl)) { SecureString passWord = new SecureString(); foreach (char c in "myPassword".ToCharArray()) passWord.AppendChar(c); clientContext.Credentials = new SharePointOnlineCredentials("myMail@myDomain.com", passWord); List oList = clientContext.Web.Lists.GetByTitle("myList"); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); […]
Debemos crear un fichero BAT (.bat) en la misma ruta de la DLL que queremos firmar. DEL .\SIGNED_LIBRARY.* /F "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\ildasm.exe" .\LIBRARY.dll /output:.\SIGNED_LIBRARY.il "C:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm.exe" .\SIGNED_LIBRARY.il /dll /key=.\LIBRARY_KEY.snk /output=.\SIGNED_LIBRARY.dll PAUSE LIBRARY = Nombre de la DLL SIGNED_LIBRARY = Nombre de la DLL firmada LIBRARY_KEY = Key que usaremos para firmar la librería (La podéis […]
Este fragmento de código nos permite hacer una llamada a un Web Service REST mediante la librería RestSharp. var client = new RestClient("REST_SERVICE_URL"); client.Authenticator = new HttpBasicAuthenticator("USER", "PASSWORD"); var request = new RestRequest(Method.GET); request.RequestFormat = DataFormat.Json; IRestResponse response = client.Execute(request); var content = response.Content;
Podemos convertir strings, chars y arrays entre si de estas formas:   string -> string[] (Todo el string en un solo elemento del Array) string[] myArray = new []{ myString };   string -> string[] (String separado en cada caracter, tratado como string) string[] myArray = myString.ToCharArray().Select(s => s.ToString()).ToArray();   string -> char[] (String separado […]
A través de esta función podemos obtener la URL para ver las propiedades de un item de una lista de SharePoint: public static string GetItemPropertiesURL(SPListItem item) { string web = item.Web.Url; string listID = item.ParentList.ID.ToString(); string contentType = item.ContentTypeId.ToString(); string itemID = item.ID.ToString(); string url = web + "/_layouts/listform.aspx?PageType=4&ListID={" + listID + "}&ID=" + itemID […]
Una interesante herramienta para crear facilmente PDFs desde HTML: NReco PdfGenerator. 1. Creamos nuestro HTML string html = "MY_HTML"; 2. Creamos una instancia del conversor var pdfConversor = new NReco.PdfGenerator.HtmlToPdfConverter(); 3. Configuramos las propiedades que necesitemos Modificar el grosor de los margenes pdfConversor.Margins = new NReco.PdfGenerator.PageMargins() { Bottom = 25, Left = 25, Right = 25, […]
SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite("YOURSITE")) { using (SPWeb web = site.OpenWeb()) { //Obtain the page PublishingPageCollection publishingPages = PublishingWeb.GetPublishingWeb(web).GetPublishingPages(); PublishingPage page = publishingPages.FirstOrDefault(f => f.Uri.AbsoluteUri == "YOURPAGE"); if (page != null) { //Allow modifications bool webAllow = web.AllowUnsafeUpdates; web.AllowUnsafeUpdates = true; SPFile file = page.ListItem.File; //Delete file.Delete(); //Restablish default permissions web.AllowUnsafeUpdates = […]
Unpublish and Checkout SharePoint Page: SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite("YOURSITE")) { using (SPWeb web = site.OpenWeb()) { //Obtain the Page PublishingPageCollection publishingPages = PublishingWeb.GetPublishingWeb(web).GetPublishingPages(); PublishingPage page = publishingPages.FirstOrDefault(f => f.Uri.AbsoluteUri == "YOURPAGEURL"); if (page != null) { //Allow file modifications bool webAllow = web.AllowUnsafeUpdates; web.AllowUnsafeUpdates = true; SPFile file = page.ListItem.File; //Unpublish […]
This is a function in order to create a CAML Query specified for Filters. Once we have the filters, we’ve to create the parameters for the function, following this template: Parameters Template Name1|Type1|Operation1|Value1,Name2|Type2|Operation2|Value2... [Operation property can only be "Equal" or "Contains", 'cause that's what I need, but it can be modified] Example Title|Text|Contains|Document,Category|Choice|Equal|Docs [Filter items […]
My case: It’s a standard register form created in a SharePoint WebPart (but this error could happen even if you’re not using SharePoint). When I submit the form, sometimes I loose the information of DropDowns (but not the information of textboxes) and it seems to happen randomly. I checked the packages sent with Wireshark and […]