none
Desarrollo en C# IDE VE que se muestre en WebPart Sharepoint 2010 "Urgente" thanks!! RRS feed

  • Pregunta

  • Saludos tengo esta duda y no se si esta bien agradezco me puedan colaborar hasta pago por esto ;) !! no se que me falta he hecho de todo!!!

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.CompilerServices;
    using System.Security;
    using System.Security.Permissions;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using System.Data.SqlClient;
    using System.Data.OleDb;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.HtmlControls;
    using System.Net.Mail;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Reflection;
    using System.Security.Principal;
    using System.Net;
    using System.Net.Mime;
    using System.Xml.Serialization;
    using System.Drawing;
    using System.Text.RegularExpressions;
    using Microsoft.SharePoint.WebPartPages;
    using System.Runtime.InteropServices;
    using System.DirectoryServices;
    using System.Security.Cryptography;
    using wsswebparts = Microsoft.SharePoint.WebPartPages;
    using aspnetwebparts = System.Web.UI.WebControls.WebParts;
    using System.ComponentModel;
    using System.Collections.ObjectModel;
    [assembly: AllowPartiallyTrustedCallers]

    namespace Extranet_Materias
    {
        public class Extranet_Materias : wsswebparts.WebPart, wsswebparts.ITransformableFilterValues
        {
            chla.DatosUsuario Dusuarios = new chla.DatosUsuario();
            GridView Grilla = new GridView();
            string _sErrDescription, mensaje, show,view;
            string[] choices = new string[5];

            protected DataTable GetDataTableFromQuery(string camlQry, SPList theList);
            //{   SPQuery listQry = new SPQuery();     listQry.Query = camlQry;  
        //    SPListItemCollection listItems = theList.GetItems(listQry);   
            return ListItems.GetDataTable(); } protected void BuildDataSet() {   
        //// get SPList objects for the lists in questions ... left as an exercise for the dev --
           //= "the CAML necessary to retreive the ites from list1";   
        //DataTable table1 = GetDataTable(camlQry, list1);    
        //table1.TableName = "Table1";   
         //DataTable table2 = GetDataTable(camlQry, list2);    
        //table1.TableName = "Table2";    
       // now build the DataSet   DataSet ds = new DataSet();     ds.Tables.Add(table1);   
        //ds.Tables.Add(table2);     ds.Tables.Add(table3);    
        //ds.Relations.Add("Table1_2", ds.Tables["Table1"].Columns["FieldA"],
        //ds.Tables["Table2"].Columns["FieldA"]);    
        //ds.Relations.Add("Table2_3", ds.Tables["Table2"].Columns["FieldB"],
        //ds.Tables["Table3"].Columns["FieldB"]);    
        //// now you can do something with these, like store them in the web part class
        //and bind them to repeaters in the web part's Render() method }

          
            public Extranet_Materias()
            {
                this.ChromeType = PartChromeType.BorderOnly;
                this.ExportMode = WebPartExportMode.All;
            }

            protected override void OnInit(EventArgs e)
            {
                try
                {
                    this.ChromeType = PartChromeType.None;
                    base.OnInit(e);
                }
                catch (Exception ex)
                {
                    _sErrDescription = "  11 " + ex.Message;
                }

            }

            protected override void CreateChildControls()
            {
                try
                {
                    base.CreateChildControls();
                    Controls.Add(Grilla);
                    Grilla.RowDataBound += new GridViewRowEventHandler(Grilla_RowDataBound);
                    if (!Page.IsPostBack)
                        CargaInfo();
                }
                catch (Exception ex)
                {
                    _sErrDescription += "   " + ex.Message;
                }
            }

            protected override void OnPreRender(EventArgs e)
            {
                Dusuarios = new chla.DatosUsuario();
                try
                {
                    int i;
                    GridViewRow row;
                    Grilla.HeaderRow.Visible = false;
                    for (i = 0; i < Grilla.Rows.Count; i++)
                    {
                        row = Grilla.Rows[i];
                        if (row.RowType == DataControlRowType.DataRow)
                        {
                            string var;
                            string url = Dusuarios.UrlTop;

                            string Msg = row.Cells[1].Text;
                            string Password = "Academica";
                            string EncryptedString = EncryptString(Msg, Password);
                            string DecryptedString = DecryptString(EncryptedString, "Academica");
                            string varurl = HttpContext.Current.Request.QueryString["var"].Replace(" ", "+");

                            var = "  <a href='" + url + "Paginas/Asignaturas.aspx?mat=" + EncryptedString + "&var=" + varurl + "'>" + row.Cells[2].Text + "</a> ";
                            row.Cells[2].Font.Name = "Tahoma";
                            row.Cells[2].Font.Size = 8;
                            row.Cells[2].Text = var;
                        }
                    }
                }
                //catch (Exception ex)
                    catch (NullReferenceException ex)
                {
                    _sErrDescription += " OnPreRender    " + ex.Message;
                }
            }

            void Grilla_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                e.Row.Cells[0].Visible = false;
                e.Row.Cells[1].Visible = false;
            }
        
            protected override void Render(HtmlTextWriter writer)
            {
                try
                {
                    Grilla.RenderControl(writer);
                    writer.Write("</BR></BR>");
                    //writer.Write(mensaje);
                    if (Dusuarios.Usuario == "juanp.lozano" || Dusuarios.Usuario == "sharepoint.admin")
                    {
                        writer.Write(_sErrDescription);
                        //writer.Write(show);
                    }
                }
                catch (Exception error)
                {
                    if (Dusuarios.Usuario == "juanp.lozano" || Dusuarios.Usuario == "sharepoint.admin")
                    {
                        writer.Write(_sErrDescription + error);
                        //writer.Write(show);
                    }
                }
            }

            private void CargaInfo()
            {
                string ins = Dusuarios.IdInscripcion;
                string var = HttpContext.Current.Request.QueryString["var"].Replace(" ", "+");
                try
                {
      string ins = Dusuarios.IdInscripcion;
      string var = HttpContext.current.Request.QueryString["var"].Replace(" ",)

               
     string DecryptedString = DecryptString(var, "Academica");

                    string sqlAA = " SELECT  dbo.MSAsignaturas.AsignaturaURL, dbo.MateriaCurso.IdMateriaCurso,  ";
                    sqlAA += " dbo.MSAsignaturas.AsignaturaEsp ";
                    sqlAA += " FROM         dbo.InscripciónMateriaCurso INNER JOIN ";
                    sqlAA += " dbo.MateriaCurso ON dbo.InscripciónMateriaCurso.IdMateriaCurso = dbo.MateriaCurso.IdMateriaCurso INNER JOIN ";
                    sqlAA += " dbo.AsignaturaGrado ON dbo.MateriaCurso.IdAsignaturaGrado = dbo.AsignaturaGrado.IdAsignaturaGrado INNER JOIN ";
                    sqlAA += " dbo.Asignaturas INNER JOIN ";
                    sqlAA += " dbo.MSAsignaturas ON dbo.Asignaturas.IdMSAsignatura = dbo.MSAsignaturas.IdMSAsignatura ON  ";
                    sqlAA += " dbo.AsignaturaGrado.IdAsignatura = dbo.Asignaturas.IdAsignatura INNER JOIN ";
                    sqlAA += " dbo.MSMaterias ON dbo.AsignaturaGrado.IdMSMateria = dbo.MSMaterias.IdMSMateria INNER JOIN ";
                    sqlAA += " dbo.Inscripción ON dbo.InscripciónMateriaCurso.IdInscripción = dbo.Inscripción.IdInscripción INNER JOIN ";
                    sqlAA += " dbo.Alumnos ON dbo.Inscripción.IdAlumno = dbo.Alumnos.IdAlumno INNER JOIN ";
                    sqlAA += " dbo.Empleados ON dbo.MateriaCurso.IdProfesor = dbo.Empleados.IdEmpleado ";
                    sqlAA += " WHERE     (dbo.MateriaCurso.Año = dbo.YearActual()) AND (dbo.Inscripción.IdInscripción = " + DecryptedString + ") ";
                    sqlAA += " ORDER BY dbo.MSAsignaturas.AsignaturaEsp ";

                    mensaje = "" + sqlAA;
                    show = "" + sqlAA;

                    DataSet DS_AA = Dusuarios.DameAllDatos(sqlAA);

                    Grilla.DataSource = DS_AA;
                    Grilla.DataBind();
                    Grilla.Font.Name = "Tahoma";
                    Grilla.Font.Size = 8;
                    Grilla.BorderColor = System.Drawing.Color.Black;
                    Grilla.GridLines = GridLines.None;
                    DS_AA.Dispose();


                }
                catch (Exception error)
                {
                    _sErrDescription += "<b>Error</b>"+ error;
                }
            }

            public static string EncryptString(string Message, string Passphrase)
            {
                byte[] Results;
                System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();

                // Step 1. We hash the passphrase using MD5
                // We use the MD5 hash generator as the result is a 128 bit byte array
                // which is a valid length for the TripleDES encoder we use below

                MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
                byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));

                // Step 2. Create a new TripleDESCryptoServiceProvider object
                TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();

                // Step 3. Setup the encoder
                TDESAlgorithm.Key = TDESKey;
                TDESAlgorithm.Mode = CipherMode.ECB;
                TDESAlgorithm.Padding = PaddingMode.PKCS7;

                // Step 4. Convert the input string to a byte[]
                byte[] DataToEncrypt = UTF8.GetBytes(Message);

                // Step 5. Attempt to encrypt the string
                try
                {
                    ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor();
                    Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length);
                }
                finally
                {
                    // Clear the TripleDes and Hashprovider services of any sensitive information
                    TDESAlgorithm.Clear();
                    HashProvider.Clear();
                }
                // Step 6. Return the encrypted string as a base64 encoded string
                return Convert.ToBase64String(Results);
            }

            public static string DecryptString(string Message, string Passphrase)
            {
                byte[] Results;
                System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
                // Step 1. We hash the passphrase using MD5
                // We use the MD5 hash generator as the result is a 128 bit byte array
                // which is a valid length for the TripleDES encoder we use below       
                MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
                byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase));
                // Step 2. Create a new TripleDESCryptoServiceProvider object
                TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider();
                // Step 3. Setup the decoder
                TDESAlgorithm.Key = TDESKey;
                TDESAlgorithm.Mode = CipherMode.ECB;
                TDESAlgorithm.Padding = PaddingMode.PKCS7;
                // Step 4. Convert the input string to a byte[]
                byte[] DataToDecrypt = Convert.FromBase64String(Message);
                // Step 5. Attempt to decrypt the string
                try
                {
                    ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor();
                    Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length);
                }
                finally
                {
                    // Clear the TripleDes and Hashprovider services of any sensitive information
                    TDESAlgorithm.Clear();
                    HashProvider.Clear();
                }
                // Step 6. Return the decrypted string in UTF8 format
                return UTF8.GetString(Results);
            }

            [wsswebparts.WebPartStorage(wsswebparts.Storage.Shared)]
            public virtual bool AllowMultipleValues
            {
                get
                {
                    return true;
                }
            }

            [wsswebparts.WebPartStorage(wsswebparts.Storage.None)]
            public virtual bool AllowAllValue
            {
                get
                {
                    return true;
                }
            }

            [wsswebparts.WebPartStorage(wsswebparts.Storage.None)]
            public virtual bool AllowEmptyValue
            {
                get
                {
                    return false;
                }
            }

            [wsswebparts.WebPartStorage(wsswebparts.Storage.None)]
            public virtual string ParameterName
            {
                get
                {
                    return "Escuela";
                }
            }

            [wsswebparts.WebPartStorage(wsswebparts.Storage.None)]
            public virtual ReadOnlyCollection<string> ParameterValues
            {
                get
                {
                    string[] values = this.Dato_();
                    return values == null ?
                        null :
                        new ReadOnlyCollection<string>(values);
                }
            }

            public string[] Dato_()
            {

                try
                {
                    string var = HttpContext.Current.Request.QueryString["var"].Replace(" ", "+");
                    //var = "VrXb3ktS42k=";

                    string DecryptedString = DecryptString(var, "Academica");

                    string sql_filtro = "SELECT CódigoMSCurso FROM  dbo.Inscripción WHERE (IdInscripción = " + DecryptedString + ")";
                    DataSet Datos_alum = Dusuarios.DameAllDatos(sql_filtro);
                    string oCurso = Datos_alum.Tables[0].Rows[0]["CódigoMSCurso"].ToString();
                    Datos_alum.Dispose();

                    string escuela;
                    try
                    {
                        int curso = int.Parse((oCurso).Substring(0, 2));
                        if ((curso >= 6) && (curso < 9)) escuela = "Escuela media";
                        else if (curso >= 9) escuela = "Bachillerato";
                        else if ((curso >= 1) && (curso <= 5)) escuela = "Primaria";
                        else escuela = "Preescolar";
                    }
                    catch
                    {
                        escuela = "Preescolar";
                    }


                    choices[0] = escuela;
                }
                catch (Exception error)
                {
                    _sErrDescription += "Dato_ " + error.Message;
                }
                return choices;
            }

            [aspnetwebparts.ConnectionProvider("Filtro Lista",
                   "ITransformableFilterValues", AllowsMultipleConnections = true)]
            public wsswebparts.ITransformableFilterValues
            SetConnectionInterface()
            {
                return this;
            }
        }
    }

     

     

     

    martes, 1 de marzo de 2011 17:32

Todas las respuestas

  • Hola camiloavall y bienvenido al foro,

    Por favor, como respeto a los demás miembros del foro, edita tu mensaje para que quede claro que problema tienes. Así te podremos responder de manera más clara y útil.

    Gracias,


    -- Edin http://edinkapic.blogspot.com
    jueves, 3 de marzo de 2011 14:50
    Moderador
  • Hola de nuevo saludos y mil disculpas mi problema es este:

    "Object reference not set to an instance of an object error."

    Segui estos pasos:

    1. Restauro un sitio Sharepoint
    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN>stsa
    dm -o addcontentdb -url "http://desarrollo2:82" -databasename WSSContent_wwwchla


    Operation completed successfully.

    umm que tal hasta aqui todo fine!!

    2. iisreset ...
    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN>iisr
    eset

    Attempting stop...
    Internet services successfully stopped
    Attempting start...
    Internet services successfully restarted

    Luego hago esto:

    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>gacutil.exe -i D:\CC-DES
    ARROLLOS\Lallama2010\WebParts\Extranet_Materias\Extranet_Materias\bin\Debug\Extr
    anet_Materias.dll
    Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Assembly successfully added to the cache      

    Luego el tercer y ultimo paso de ensamble :

    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>iisreset

    Attempting stop...
    Internet services successfully stopped
    Attempting start...
    Internet services successfully restarted

     

    Esta parte se que esta bien ahora creo que mi inconveniente esta instando algun objeto en la webpart (source)....I don't know make it :( help me please!!

     

    jueves, 10 de marzo de 2011 19:01