A través de la terminal de VS Code debemos navegar a la carpeta donde esta situado el proyecto en el que queremos añadir el paquete Nuget. Una vez ahí, ejecutamos: dotnet add package Newtonsoft.Json Nota: Debéis instalar la extension de C# para VS Code. Mas información aquí: https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio-code
Categoría: C#
Crear Item en Lista de SharePoint usando CSOM
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(); …
Firmar DLLs (Microsoft IL Disassembler-Assembler)
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 …
Sigue leyendo Firmar DLLs (Microsoft IL Disassembler-Assembler)
Obtener Datos de Servicio REST con RestSharp
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;
Convertir string en string[] o char[] y viceversa
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 …
Sigue leyendo Convertir string en string[] o char[] y viceversa
Convertir HTML en PDF en C#
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, …
Delete SharePoint Page Programmatically
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 = …
Checkin/Publish and Unpublish/Checkout SharePoint Pages Programmatically
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 …
Sigue leyendo Checkin/Publish and Unpublish/Checkout SharePoint Pages Programmatically
CAML Query Auto-Created in C# with Loops
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 …
Empty DropDown After Submit your Form and Information Lost
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 …
Sigue leyendo Empty DropDown After Submit your Form and Information Lost