lunes, 29 de julio de 2013

How with javascript? Read SharePoint list Items using javascript.

In this post , you learn to read list items, using javascript.


Prerequisites.

A sharepoint list:

SharePoint List Name : ItemsSharePoint
Fields:

  • Title = Single line of text.
  • TextColumn = Single line of text.


1. Insert a content editor webpart, into a principal page. (see next image).


2. Open new notepad and paste the next code.


Code.

 Read Items Title  
 <br/>  
 <INPUT TYPE="button" VALUE="Read Items" onClick="ReadItem()">  
 <script type="text/javascript">  
 var siteUrl = '/sites/ejemplossharepoint';  
 var ListItems;  
 function ReadItem()   
 {  
      var clientContext = new SP.ClientContext(siteUrl);  
      var oList = clientContext.get_web().get_lists().getByTitle('ItemsSharePoint');  
      var query = new SP.CamlQuery();  
      query.set_viewXml("<View><Query><ViewFields><FieldRef Name='Title' /></ViewFields><ViewFields><FieldRef Name='Title' /></ViewFields></Query></View>");  
      ListItems= oList.getItems(query);  
      clientContext.load(ListItems);  
      clientContext.executeQueryAsync(Function.createDelegate(this, this.Succeeded), Function.createDelegate(this, this.Failed));  
 }  
 function Succeeded() {  
  var listEnumerator = ListItems.getEnumerator();  
  while (listEnumerator.moveNext()) {  
   alert("Text of list item : " + listEnumerator.get_current().get_item("Title") + listEnumerator.get_current().get_item("TextColumn"));  
  }   
 }  
 function Failed(sender, args) {  
  alert('Error: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());  
 }  
 </script>  



3. Save the notepad in a document library as "CodeRead" and then copu Shortcut  (see next image).



4. Edit content editor web part, and paste the link into "content link".



5. Test.



easily.

Regards.
Oscar Miguel Dominguez Acevedo

miércoles, 24 de julio de 2013

Hide a Ribbon Button, using a Visual Web Part Sharepoint 2010



1.In a Visual Studio solution create new Visual Web Part.


2. Add the next Reference.


3. Add the next code.



4. Run, and add the Visual Web Part into the list page



Now, you will notice that the New Folder button does not appear




Here Default Server Ribbon Customization Locations you find the list of all Button in the Ribbon

Code

 using System;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 using System.Web.UI.WebControls.WebParts;  
 using Microsoft.SharePoint;  
 using Microsoft.SharePoint.WebControls;  
 using Microsoft.Web.CommandUI;  
 namespace ProyectosSharePoint.HideRibbonButton  
 {  
   public partial class HideRibbonButtonUserControl : UserControl  
   {  
     protected void Page_Load(object sender, EventArgs e)  
     {  
       SPRibbon oRibbon = SPRibbon.GetCurrent(this.Page);  
       oRibbon.TrimById("Ribbon.ListItem.New.NewFolder");  
     }  
   }  
 }  


easily =)

Regards.
Oscar Miguel Dominguez Acevedo.

lunes, 22 de julio de 2013

How create CAML Queries easily for SharePoint 2010?, read the next post.

For CAML queries easily in SharePoint, only need to use "U2U Caml Query Builder Solution Package for SharePoint 2010". The following post show how install and use this wsp.

1. Download Here.

2. Paste .wsp into c:

3. Execute SharePoint 2010 Management Shell  to Administrator



4. Execute Add-SPSolution, see next image.


5. Install solution.


6. go to SharePoint site, the the option  Site Settings ---> Site Collection Fetures and activate U2U feature.


7. Now, you see the U2U option in the Ribbon


8. Test.




Easily =)

Regards
Oscar.

viernes, 19 de julio de 2013

Insert Item in SharePoint list using javascript

The next post show the way to insert an item in sharepoint list using javascript.

Pre Requisites.
one sharepoint list.

1. In the main page, insert a content editor


2. Now, in a notepad insert the next code

Code


 Item Title  
 <br/>  
 <input id="Text1" type="text"/>  
 <br/>  
 <INPUT TYPE="button" VALUE="CrearLista" onClick="createListItem()">  
 <script type="text/javascript">  
 function createListItem()   
 {  
   var siteUrl = '/sites/ejemplossharepoint';  
   var Context = new SP.ClientContext(siteUrl);  
   var oList = Context.get_web().get_lists().getByTitle('ItemsSharePoint');  
   var itemCreateInfo = new SP.ListItemCreationInformation();  
   this.oListItem = oList.addItem(itemCreateInfo);  
   oListItem.set_item('Title', document.getElementById('Text1').value);  
   oListItem.update();  
   Context.load(oListItem);  
   Context.executeQueryAsync(Function.createDelegate(this, this.Succeeded), Function.createDelegate(this, this.Failed));  
 }  
 function Succeeded()   
 {  
   alert('Item number:' + oListItem.get_id() + ' was created');  
 }  
 function Failed(sender, args)   
 {  
   alert('Error:' + args.get_message() + '\n' + args.get_stackTrace());  
 }  
 </script>  

3. Save the document as "Code".


4. Create a document library with the name CodeLibrary and add the file "Code".



5. Copy the file link.


6. Edit the content editor and paste the file link.


7. test and verify.




easily =D

Regards.
Oscar Miguel Dominguez Acevedo.

miércoles, 17 de julio de 2013

Read items from a SharePoint 2010 List programmatically

There are many ways to read programmatically items from a Sharepoint List. but in this post see a simple way to read



1. we have a SharePoint list with many elements

2. We will pass through the columna "Title", using the next code


It's is the simple way in SharePoint


Code.


 using System;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 using System.Web.UI.WebControls.WebParts;  
 using Microsoft.SharePoint;  
 namespace ProyectosSharePoint.LeerItems  
 {  
   public partial class LeerItemsUserControl : UserControl  
   {  
     protected void Page_Load(object sender, EventArgs e)  
     {  
       SPWeb Web = SPContext.Current.Web;/// web context  
       SPList List = Web.Lists["ItemsSharePoint"]; ///Name of list  
       foreach (SPItem item in List.Items)  
       {  
         string ItemValue = item["Title"].ToString();///value of the field  
       }  
     }  
   }  
 }  


Regards.
Oscar Miguel Dominguez Acevedo

lunes, 15 de julio de 2013

SharePoint 2010 - Update xml in a SharePoint forms Library programmatically.

It's posible programatically update a xml form in a SharePoint form library, the next post shows the way.




Scenary

In a form library, you need update the field "Email"  value  in all forms at the same time. In this case, the possible solution  open one by one the forms, but this is slow, now the best way is programming.


1. First, locate the form library.



2. Find the field who need update




3. Create a visual webpart  to place the code. Insert one textbx and a Button. See the next image.


4. Now, add the next code in the click event to our button


5. Execute and test.


6. With this, the field "Email" is updated in all forms from our library

Code.

 using System;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 using System.Web.UI.WebControls.WebParts;  
 using System.Xml;  
 using Microsoft.SharePoint;  
 using System.IO;  
 namespace ProyectosSharePoint.UpdateXml  
 {  
   public partial class UpdateXmlUserControl : UserControl  
   {  
     protected void Page_Load(object sender, EventArgs e)  
     {  
     }  
     protected void Button1_Click(object sender, EventArgs e)  
     {  
       System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); /// New Xml Document  
       SPWeb web = SPContext.Current.Web; /// current context  
       SPFolder FolderXML = web.GetFolder("Formulaio"); /// folder name  
       foreach (SPFile File in FolderXML.Files)  
       {  
         byte[] XmlFormData = File.OpenBinary();/// open file  
         System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();  
         using (MemoryStream ms = new MemoryStream(XmlFormData))  
         {  
           MemoryStream ms2 = new MemoryStream();  
           xmldoc.Load(ms);/// load Xml  
           XmlNodeList nodes = xmldoc.GetElementsByTagName("my:Email");/// Node  
           nodes.Item(0).InnerText = TextBox1.Text;/// Update Node with textbox value  
           xmldoc.Save(ms2);///Save xmldoc in new MemoryStream ms2  
           ms.Close();/// close  
           File.SaveBinary(ms2);/// save file with new MemoryStream  
         }  
       }  
     }  
   }  
 }  

Regards.
Oscar Miguel Dominguez Acevedo.

jueves, 11 de julio de 2013

Usando la libreria DocX en SharePoint Parte III - Usando Custom properties en Word (DocX Library in SharePoint 2010 Part III - Custom Properties)

In this chapter we learn, how to use custom properties in a Word Document

In the latest chapters we have reviewed the Docx library, in this chapter we will continue, inserting custom properties in the Word document.





1. Open Word and create new document, see the next image.




2. In the tab "file", go to properties and select custom properties.



3. In the tab "custom", type: "MyName" and  the tab value type: "MyName", then press Add



4. Now, add our custom property.


5. Once you have everything ready, save the word document as "CustomPropertyTemplate.docx" and close Word.

6. Now go to sharePoint library and select open with explorer, see the next image.


7. when you open the folder, appears a new hidden folder called Forms, open this folder and paste the word document..






8. go to visual studio solution and create a new visual web part..
9. In the design view add a texbox and a button, see the next image.


10. then you add the next code in the clic event of the button.


11. All code  has already been reviewed previously, the most important it's the following code line.

                Doc.AddCustomProperty(new CustomProperty("MyName", TextBox1.Text));
                Doc.Save();

With this property, you can storing the textbox value.

12. execute and test.




And so we can handle custom properties.

Code.

 using System.Web.UI.WebControls.WebParts;  
 using Novacode;  
 using Microsoft.SharePoint;  
 using System.IO;  
 using System.Text;  
 namespace ProyectosSharePoint.CustomProperties  
 {  
   public partial class CustomPropertiesUserControl : UserControl  
   {  
     protected void Page_Load(object sender, EventArgs e)  
     {  
     }  
     protected void Button1_Click(object sender, EventArgs e)  
     {  
       SPWeb Web = SPContext.Current.Web;  
       SPFile FileWord = null;  
       FileWord = Web.GetFile(Web.Url + "/DocxDocumentos/Forms/CustomPropertyTemplate is.docx");  
       Stream readStreamNovaCode = FileWord.OpenBinaryStream();  
       using (DocX Doc = DocX.Load(readStreamNovaCode))  
       {  
         Doc.AddCustomProperty(new CustomProperty("MyName", TextBox1.Text));  
         Doc.Save();  
         SPList olist = Web.Lists["DocxDocumentos"];  
         String url = olist.RootFolder.ServerRelativeUrl.ToString();  
         SPFolder newfolder = Web.GetFolder(url + "/");  
         SPFile uploadedFileDocNova = newfolder.Files.Add(newfolder.Url + @"/" + TextBox1.Text + ".docx", readStreamNovaCode, true);  
       }  
     }  
   }  
 }  

Regards.
Oscar Miguel Dominguez Acevedo.

miércoles, 10 de julio de 2013

Usando la libreria DocX en SharePoint Parte II - Manipulando tablas en Word (DocX Library in SharePoint 2010 Part II - Using tables in word)

Manipular las tablas usando la librería DocX es muy sencillo retomando el ejemplo que teníamos en nuestro post anterior Usando la libreria DocX en SharePoint Parte I - Creación de Documentos Word (DocX Library in SharePoint 2010 Part I - word document creation) agregaremos una funcionalidad extra insertado una tabla con algunas de sus propiedades.

1. El siguiente código lo único que hace es crear un documento con una linea de texto en word.



2. Agregamos la referencia a System.Drawing


Nota: es necesario que agreguemos el espacio de nombres using System.Linq

3. Agregamos el código que esta seleccionado en la siguiente imagen.


3. una vez que ejecutamos nuestra aplicación nuestro documento Word se visualiza de la siguiente manera.



Con esto podemos ver que podemos crear tablas sin problema alguno utilizando nuestra librería de DocX, existen otras propiedades, de las cuales hablaremos en otros post.




regards.
Oscar Miguel Dominguez Acevedo.