Tuesday, March 29, 2011

new Domains

arab cooking guide

Tuesday, August 31, 2010

HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET

Use this step-by-step guide to dynamically create controls for an .aspx page.

This article demonstrates how to dynamically create a control for an .aspx page. The sample project does the following:

Creates two TextBox controls.
Verifies that the contents (TextBox.text) and the attributes of the TextBox are saved across posts to the server.
Illustrates handling events that are posted by a dynamically-created control.



Create the Project and Static Control


Start Microsoft Visual Studio .NET.
On the File menu, point to New, and then click Project.




Click Visual C# Projects under Project Type, and then click ASP.NET Web Application under Templates. Name the project DynamicCreate.





Open the WebForm1.aspx file, and switch to HTML view. Replace the existing code between the and tags with the following code:




TextBox2:
TextBox1:












Return Design view to see the statically-created controls that the project will use.









Create the Dynamic Control and Hook It Up


  1. In Solution Explorer, click Show All Files to display a list of the files that are associated with WebForm1.aspx. Open the WebForm1.aspx.cs file.
  2. Declare the TextBox controls in the .cs (code-behind) file. Also, declare a variable for the existing form element in the .aspx file. Update the declarations following the declaration for the WebForm1 class:













    public class WebForm1 : System.Web.UI.Page
    {
     protected System.Web.UI.WebControls.Label Label1;
     protected System.Web.UI.WebControls.Label Label2;
     protected System.Web.UI.WebControls.Label Label3;
     protected System.Web.UI.WebControls.Label Label4;
     protected System.Web.UI.WebControls.Button Button1;
    
     // Added by hand for access to the form.
     protected System.Web.UI.HtmlControls.HtmlForm Form1;
     
     // Added by hand; will create instance in OnInit.
     protected System.Web.UI.WebControls.TextBox TextBox1;
     protected System.Web.UI.WebControls.TextBox TextBox2;
    The TextBox declarations are entered by hand as they would be if a TextBox were dragged from the toolbox to the .aspx page. However, in this case, you create the controls dynamically.
  3. Add code to create the TextBox controls dynamically. The controls are created every time that the page is run. The best place to do this is in the OnInit function that the WebForm1 class provides.

    Locate the OnInit function. Expand the code that is marked with the "Web Form Designer generated code" comment. Modify the OnInit function so that it looks similar to the following code:













    override protected void OnInit(EventArgs e)
    {
        // Create dynamic controls here.
        // Use "using System.Web.UI.WebControls;"
        TextBox1 = new TextBox();
        TextBox1.ID = "TextBox1";
        TextBox1.Style["Position"] = "Absolute";
        TextBox1.Style["Top"] = "25px";
        TextBox1.Style["Left"] = "100px";
        Form1.Controls.Add(TextBox1);
    
        TextBox2 = new TextBox();
        TextBox2.ID = "TextBox2";
        TextBox2.Style["Position"] = "Absolute";
        TextBox2.Style["Top"] = "60px";
        TextBox2.Style["Left"] = "100px";
        Form1.Controls.Add(TextBox2);
    
        this.TextBox1.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
        this.TextBox2.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
    
        // 
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        // 
        InitializeComponent();
        base.OnInit(e);
    }
    This code dynamically creates two TextBox controls, sets their IDs and positions, and then binds them to the Form Controls collection. The code also wires up the TextChanged events of the text boxes to a handler (TextBox_TextChanged).

    Other than setting the TextBox position programmatically and binding it to the Form Controls collection, you can add Web Forms Panel controls to the .aspx page and bind the text boxes to those in the OnInit function, similar to this:













    TextBox1 = new TextBox();
        TextBox1.ID = "TextBox1";
    //Form1.Controls.Add(TextBox1);
        Panel1.Controls.Add(TextBox1);
    Note When you create dynamic controls on a Web Form, the controls must be created and added to the controls collection either in the OnInit or in the Page_Load events. Otherwise, the controls behave unexpectedly.
  4. Initialize the Text property and styles for the text boxes. Modify the existing Page_Load function as follows:













    private void Page_Load(object sender, System.EventArgs e)
    {
        if(!IsPostBack)
        {
            // Set the initial properties for the text boxes.
            TextBox1.Text = "TextBox1";
            TextBox2.Text = "TextBox2";
        }
    }
    The initial value of the text boxes (if(!IsPostBack)) is set one time. This information is maintained by the IPostBackDataHandler interface for the text boxes, making it unecessary to reset the value for subsequent posts.
  5. Provide a handler for the TextChanged events of the TextBox control. Add the following code after the Page_Load function body:













    private void TextBox_TextChanged(object sender, System.EventArgs e)
    {
        TextBox txtBoxSender = (TextBox)sender;
        string strTextBoxID = txtBoxSender.ID;
    
        switch(strTextBoxID)
        {
            case "TextBox1":
                Label3.Text = "TextBox1 text was changed";
                break;
            case "TextBox2":
                Label4.Text = "TextBox2 text was changed";
                break;
        }
    }
    This code checks to see which control triggered the event and then reports this to the user by using the approprite Label control. Notice that this function handles the TextChanged event for both of the dynamically-created TextBox controls. By default, AutoPostBack is false for the TextBox controls. Therefore, changing the text in the controls does not cause a PostBack to the server. However, when the Submit button is clicked to post the form to the server, the TextChanged events for the TextBox controls are triggered, and this function is called.



Save, Build, and Run the Sample

Save and build the sample. To run it in Visual Studio .NET, right-click the .aspx file, and then click View in Browser.

Tuesday, February 23, 2010

Access Denied Error Message While Editing Properties of any Document in a MOSS Document Library

When we go to properties of any document in document library even with full permission, we get access denied message if we try to edit the document properties. However we can open and edit the document successfully.


This is one of those errors that you spend a lot of time troubleshooting without a clue of why this is happening. As an experienced MOSS developer, you probably assume this is a permission issue; With this assumption, you use farm administrator account to log into the site, still you get access denied error page. You tried so many other steps, all to no avail. There is a good news and a bad news. Which one will you like me to talk about first? Just kidding!


Ok. The Good news is that you did not create or cause this issue. The bad news is that it is a bug. I’ve called and discussed this with the folks at Microsoft. There are two ways to fix this. Use step 1 to fix this issue in existing document libraries. Use step 2 to fix it in existing list templates



Step 1. For existing lists, you can run the following code to fix it. This here is a sample peace of code that should add the appropriate attribute to the list having the issue:


void FixField()

{

string RenderXMLPattenAttribute = “RenderXMLUsingPattern”

string weburl = “<http://localhost>”

string listName = “test2″

SPSite site = new SPSite(weburl);

SPWeb web = site.OpenWeb();

SPList list = web.Lists[listName];

SPField f = list.Fields.GetFieldByInternalName(“PermMask”);

string s = f.SchemaXml;

Console.WriteLine(“schemaXml before: ” + s);

XmlDocument xd = new XmlDocument();

xd.LoadXml(s);

XmlElement xe = xd.DocumentElement;

if (xe.Attributes[RenderXMLPattenAttribute] == null)

{

XmlAttribute attr = xd.CreateAttribute(RenderXMLPattenAttribute);

attr.Value = “TRUE”

xe.Attributes.Append(attr);

}

string strXml = xe.OuterXml;

Console.WriteLine(“schemaXml after: ” + strXml);

f.SchemaXml = strXml;

}

 
Step 2: For existing stp (list templates) that are having this problem, you should be able to modify the manifest.xml to add the attribute, and repackage the stp. You simply would rename the .stp file to a .cab file, open the manifest.xml file packaged in the cab, make this change that is highlighted:



Name=”PermMask”

SourceID=”http://schemas.microsoft.com/sharepoint/v3

StaticName=”PermMask”

RenderXMLUsingPattern=”TRUE”

Group=”_Hidden”

ReadOnly=”TRUE”

Hidden=”TRUE”

ShowInFileDlg=”FALSE”

Type=”Computed”

DisplayName=”$Resources:core,Effective_Perm_Mask;”>
















Then repackage the manifest.xml file to a .cab file and rename it back to .stp. Upload the list template to the template gallery. Any subsequent lists created with this template should work as expected.

Microsoft promised to fix this in the next hotfix. Please note that to prevent new list templates from having this problem, you will need to update the fieldswss.xml via the next Hotfix. Please do not update fieldswss.xml manually.

Tuesday, December 22, 2009

SharePoint 2010...What's Next? - Webcast Archive





Thanks for attending the webcast!

Please find the link to the archived webcast here:


Please find the link to the PowerPoint presentation here:

FW: BA-Insight - SharePoint Search 2010 What's  Next? - December 8th - Webcast recordning

i have got the  mail : 

Subject: BA-Insight - SharePoint Search 2010 What's  Next? - December 8th - Webcast recordning




We thank you for your interest in the "SharePoint Search 2010.. What's next?" Webcast, the 8th of December 2009.
A recording of the Webcast can be found on the following link: https://www2.gotomeeting.com/register/408732530
Please find the link to the PowerPoint presentation here: http://downloads.ba-insight.net/downloads/sps2010whatsnext.pptx
We would also like to provide you with more information about our approach on how to improve the Search capabilities on Microsoft SharePoint, WSS and Microsoft Search Server.
BA-Insight provides both a dramatically improved Search experience on SharePoint (See below description) and SharePoint/FAST connectivity with a range of Connectors to Enterprise solutions such as MS Exchange, MS Dynamics CRM, MS SQL, SAP, Oracle, Lotus Notes, Symantec Enterprise Vault and a wide range of Document Management systems (Documentum, Hummingbird, Interwoven etc). See description on our web site: http://ba-insight.net/Products.html. For Connectors not on the list, please contact us.
The Longitude Search solution for SharePoint 2010, MOSS 2007, WSS 3.0 or MS Search Server provides users with dramatic usability improvement leading to faster portal adoption.
Longitude Search for SharePoint will provide the following key enhancement to your SharePoint 2010, MOSS 2007 and WSS 3.0 Search.:
·         Document/ Page Previews - Users are presented with the most relevant page in the document instantly. Watch the Video Demo (http://168.100.10.22/videos/usability/usability.html)
·         Parametric Navigation - Often called Guided Navigation, Parametric enables users to build complex queries leveraging any meta-data that is available. Parametric Navigation is Advanced Search as it was meant to be. Watch the Video Demo (http://168.100.10.22/videos/parametric/parametric.html)
·         Enhanced People / Expertise Search - Longitude provides essential features to MOSS People Search. Faceted/Drilldown Navigation, Support for multi-value fields, Wild Card operators, Enhanced Sorting Capability and More! Watch the Video People Search Demo (http://168.100.10.22/videos/peoplesearch/peoplesearch.htm) or Video Faceted/Wildcard Search Demo  (http://168.100.10.22/videos/wildcard/Wildcard2.html )
·         Relevance Optimization - Longitude automatically tunes and optimizes the SharePoint ranking algorithm to the unique characteristics of your company.
·         Automatic meta-data tagging - Users automatically tag relevant content when they search for information and find relevant content.
For more in-depth information about Longitude, we hope you will find the following links helpful:
·         For a quick overview of the Longitude Search features, please go to: http://ba-insight.net/search-solutions2.html
·         If you are interested in a good introduction to features and functions in Longitude Search for SharePoint please see our demo video series: http://www.ba-insight.net/enterprise-search-demo.html
·         Learn more about the Longitude technical details and architecture from our downloadable white papers: http://www.ba-insight.net/longitude-documentation.html
·        Longitude Search will be SharePoint 2010 Ready already in February 2010 – Please request our Product Road Map!!
Evaluation software is also available and if you are interested in a Live Demo please don't hesitate to contact them .

Monday, December 14, 2009

Start Workflow From c# Code



   1:   Guid wfBaseId = new Guid("{32601603-2149-447A-BD73-E64AF9307D6F}"); 
   2:              SPSite site = new SPSite(ConfigurationManager.AppSettings["SharepointSite"].ToString()); 
   3:              SPWeb web = site.OpenWeb(ConfigurationManager.AppSettings["SharepointWeb"].ToString());
   4:              SPList list = web.Lists["genericDocs"]; 
   5:              SPListItem item = list.Items[0];
   6:             
   7:   
   8:   
   9:   
  10:              SPWorkflowAssociation associationTemplate= list.WorkflowAssociations.GetAssociationByBaseID(wfBaseId); 
  11:              site.WorkflowManager.StartWorkflow(item, associationTemplate, "",true);

Windows Service That Starting Workflow by Code every X Time



   1:   
   2:   
   3:   
   4:  using System;
   5:  using System.Collections.Generic;
   6:  using System.ComponentModel;
   7:  using System.Data;
   8:  using System.Diagnostics;
   9:  using System.Linq;
  10:  using System.ServiceProcess;
  11:  using System.Text;
  12:  using System.Configuration;
  13:  using System.Threading;
  14:  using Microsoft.SharePoint;
  15:  using Microsoft.SharePoint.Workflow;
  16:  using System.Collections.Specialized;
  17:  namespace AlertWinService
  18:  {
  19:      public partial class AlertWinService : ServiceBase
  20:      {
  21:   
  22:          #region Class Members
  23:          private bool m_bFirstLoop = true;
  24:          private string m_LogLevel = "";
  25:          public DataTable Mainresultdt = null;
  26:          SPListItem currentListitem = null;
  27:          System.Timers.Timer timer1 = new System.Timers.Timer();
  28:          #endregion
  29:          public AlertWinService()
  30:          {
  31:              InitializeComponent();
  32:          }
  33:   
  34:          
  35:          private string querybuilder(StringCollection andClauses)
  36:          {
  37:              StringBuilder sb = new StringBuilder();
  38:              sb = sb.Append("&lt;Where&gt;");
  39:   
  40:              //only 1 item
  41:              if (andClauses.Count == 1)
  42:              {
  43:   
  44:                  sb = sb.Append(andClauses[0].ToString());
  45:   
  46:              }
  47:              //When the count is 2, we need to add one ‘And’ clause and add both item to be searched for
  48:              //two items
  49:              else if (andClauses.Count == 2)
  50:              {
  51:                  sb = sb.Append("&lt;And&gt;" + andClauses[0].ToString() + andClauses[1].ToString() + "&lt;/And&gt;");
  52:              }
  53:              //When the item count is greater than 2, we will add the ‘And’ clauses based on the count – 1.
  54:              else if (andClauses.Count &gt; 2)
  55:              {
  56:                  for (int i = andClauses.Count - 1; i &gt; 0; i--)
  57:                  {
  58:                      sb = sb.Append("&lt;And&gt;");
  59:                  }
  60:                  //After adding the proper number of clauses we will add the first two items and 
  61:                  //close the first ‘And’ clause off. 
  62:                  //Then, as we loop through the remaining items, we add another ‘And’ clause after each 
  63:                  //iteration and close then set.  
  64:                  // If you were to add ‘Or’ clauses, you could do the same.
  65:                  sb = sb.Append(andClauses[0].ToString() + andClauses[1].ToString() + "&lt;/And&gt;");
  66:                  for (int j = 2; j &lt; andClauses.Count; j++)
  67:                  {
  68:                      sb = sb.Append(andClauses[j].ToString() + "&lt;/And&gt;");
  69:                  }
  70:              }
  71:              //Finally we close the entire set off by adding the closing ‘Where’ clause.
  72:   
  73:              sb = sb.Append("&lt;/Where&gt;");
  74:   
  75:              return sb.ToString();
  76:          }
  77:   
  78:          protected override void OnStart(string[] args)
  79:          {
  80:              NetvisionLogger.WriteTolog("onstart");
  81:              SetTimerInfo();
  82:   
  83:   
  84:   
  85:   
  86:          }
  87:   
  88:          private void SetTimerInfo()
  89:          {
  90:              int iTimerIntervalMinutes = 60 * 24; // default is 24 hours interval
  91:              string sTimerIntervalMinutes = string.Empty;
  92:             
  93:              if (m_bFirstLoop)
  94:              {
  95:                  //m_LogLevel = ConfigurationManager.AppSettings["ExportLogLevel"].ToString().ToUpper();
  96:                  sTimerIntervalMinutes = ConfigurationManager.AppSettings["ExportServiceStartDelayInMinutes"];
  97:              }
  98:              else
  99:              {
 100:                  this.timer1.Stop();
 101:                  sTimerIntervalMinutes = ConfigurationManager.AppSettings["ExportTimerIntervalMinutes"];
 102:              }
 103:              
 104:              //    System.Diagnostics.EventLog.WriteEntry("Train_PublicApplicationsExport", "SetTimerInfo - setting timer interval to: " + sTimerIntervalMinutes, EventLogEntryType.Information, 888);
 105:              // to do Update the splist item  
 106:   
 107:   
 108:             NetvisionLogger.WriteTolog("SetTimerInfo - setting timer interval to:" + sTimerIntervalMinutes + " Minutes");
 109:             if (!string.IsNullOrEmpty(sTimerIntervalMinutes))
 110:              {
 111:                  iTimerIntervalMinutes = Convert.ToInt32(sTimerIntervalMinutes);
 112:              }
 113:             this.timer1.Interval = (1000 * 60) * iTimerIntervalMinutes;
 114:              this.timer1.Enabled = true;
 115:              this.timer1.Elapsed+=new System.Timers.ElapsedEventHandler(timer1_Elapsed);
 116:             
 117:              this.timer1.Start();
 118:              
 119:          }
 120:   
 121:          void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 122:          {
 123:              NetvisionLogger.WriteTolog("Alert Windows Service WorkFlow Start");
 124:                     
 125:         
 126:           
 127:   
 128:              // workflow based id 
 129:              /*Guid wfBaseId = new Guid("{32601603-2149-447A-BD73-E64AF9307D6F}"); 
 130:              SPSite site = new SPSite(ConfigurationManager.AppSettings["SharepointSite"].ToString()); 
 131:              SPWeb web = site.OpenWeb(ConfigurationManager.AppSettings["SharepointWeb"].ToString());
 132:              SPList list = web.Lists["genericDocs"]; 
 133:              SPListItem item = list.Items[0];*/
 134:              /*site.AllowUnsafeUpdates = true;
 135:              item["Title"] = "Alert Windows Service";
 136:              item.Update();
 137:              site.AllowUnsafeUpdates = false;*/
 138:   
 139:   
 140:   
 141:              /*SPWorkflowAssociation associationTemplate= list.WorkflowAssociations.GetAssociationByBaseID(wfBaseId); 
 142:              site.WorkflowManager.StartWorkflow(item, associationTemplate, "",true);*/
 143:   
 144:              SPSecurity.RunWithElevatedPrivileges(delegate()
 145:                 {
 146:                     UpdateSharepointDocumentLibrary();
 147:                 });
 148:   
 149:   
 150:          }
 151:   
 152:   
 153:          private void UpdateSharepointDocumentLibrary()
 154:          {
 155:   
 156:              using (SPSite site = new SPSite(ConfigurationManager.AppSettings["SharepointSite"].ToString()))
 157:              { 
 158:              
 159:                  using (SPWeb web= site.OpenWeb(ConfigurationManager.AppSettings["SharepointWeb"].ToString()))
 160:                  {
 161:                     //SPDocumentLibrary doclib= new SPDocumentLibrary();
 162:                      SPFolder doclib = web.Folders[ConfigurationManager.AppSettings["SharepointDocLib"].ToString()];
 163:                      StringCollection andClauses = new StringCollection();
 164:   
 165:                      SPList list = web.Lists["genericDocs"]; 
 166:                      // if therer is a keyword         
 167:                      andClauses.Add("&lt;Contains&gt;&lt;FieldRef Name='Title'/&gt;&lt;Value Type='Text'&gt;AlertWeb&lt;/Value&gt;&lt;/Contains&gt;");
 168:   
 169:   
 170:   
 171:   
 172:   
 173:   
 174:   
 175:                      SPQuery query = new SPQuery();
 176:                      query.Query = querybuilder(andClauses);
 177:   
 178:                      SPListItemCollection currentlistitemcoll = list.GetItems(query);
 179:                      foreach (SPListItem item in currentlistitemcoll)
 180:                      {
 181:                          currentListitem = item;
 182:                          break;
 183:   
 184:                      }
 185:                      // resultdt
 186:                      Mainresultdt = list.GetItems(query).GetDataTable();
 187:                      Random rr=new Random();
 188:                      site.AllowUnsafeUpdates = true;
 189:                      currentListitem["numberofworkflow"] = rr.Next();
 190:                      currentListitem.Update();
 191:                      site.AllowUnsafeUpdates = false;
 192:   
 193:                  }
 194:              }
 195:          }
 196:   
 197:          void timer1_Tick(object sender, EventArgs e)
 198:          {
 199:             
 200:              /*this.timer1.Stop();*/
 201:              NetvisionLogger.WriteTolog("Tick");
 202:              /*this.timer1.Start();*/
 203:          }
 204:         
 205:          
 206:          protected override void OnStop()
 207:          {
 208:   
 209:              timer1.Stop();
 210:          }
 211:      }
 212:  }
 213: