Mostrando entradas con la etiqueta DocX Library. Mostrar todas las entradas
Mostrando entradas con la etiqueta DocX Library. Mostrar todas las entradas

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.

lunes, 8 de julio de 2013

Usando la libreria DocX en SharePoint Parte I - Creación de Documentos Word (DocX Library in SharePoint 2010 Part I - word document creation)

A excellent option to manipulate word documents is the DocX library, you have download, in the next link DocX Library. On a series of chapters I will show a easy form to manipulate this DLLL for their sharepoint projects.

In this first chapter, we will see how make a Word document using this library and saving it in a sharepoint library


1. We must have our own document library in a sharepoint site, in my case I create a library called DocxDocumentos and only verify that this is a Word template


2. In our Visual Studio solution, create our Visual Web Part with the title DocxNuevoElemento.


3. On the design view add a texbox and one button, as seen on the next image,


4. In our project, add a new reference, in the browse section search and add our dll.


5. Add our name space.



6. Now... write, the next code in a click event


7. It's necesary to add  our DocX.dll on the bin folder, before to run.



8. run our code and to load the page add our webpart


9 Placed in the Textbox "Primer Documento" (First Document) and then click on the button. Now, we can see the document in our library.



10. If you open the document we can see a paragraph.


In this manner we can see to Word document creation it's very easy. In the next chapters see all the benefits of this library.

Saludos.
Oscar Miguel Dominguez Acevedo.