Wednesday 25 April 2012

SP IMPORTANT QUESTIONS_ 1

How to Compare The Two data table Columns in C sharp

Q)I have one issue , my issue is
1)i want to compare the two data table columns in C sharp
2) if columns in first datatable matches with columns in second datatable
3) i want to copy those matched column data to another datatable

please help me how to do it.
By using  your code we can compare but  if the column matches with other i want to copy entire column data to another datatable .
eg;
datatable 1                                                  datatable 2
col1   col2   col3                                          col1     col2
1       test     mumbai                                       1       test
2       test     london                                         2      cool
3       test2   america                                        3       testing


i want to matched column data to another datatable
datatable 3
col1   col2
1        test
2
3


Answer)

DataTable datatable1=null; //Your Datatable1
DataTable datatable2=null; //Your Datatable2
DataTable dtMatchData = new DataTable("dtMatchData");
        dtMatchData = datatable1.Copy();
        foreach (DataColumn dt1col in datatable1.Columns)
        {
            if (datatable1.Columns.Contains(Convert.ToString(datatable2.Columns[dt1col.ColumnName])) == false)
            {
                dtMatchData.Columns.Remove(dt1col.ColumnName);

            }
        }


 

Tuesday, February 28, 2012

Default Databases Created in SQL Server After Sharepoint 2010 Installation

These are the databases that are created after sharepoint 2010 installation.







Content Query WebPart (CQWP) in SharePoint 2010

The Content Query Web Part is a tool that site designers can use to aggregate interesting and relevant slices of information on web page by letting you build queries through an easy to use UI and then display that content in unique, configurable ways.



The CQWP is designed to return roll-up content over several different scopes, anywhere from a single a list or library, to all lists or libraries across an entire Site Collection.  In SharePoint 2010, the CQWP single list query is also optimized to work over large single libraries, taking advantage of smart indices and other tools designed to improve query performance over large document libraries.

Content Query WebPart comes first in MOSS 2007, but in SharePoint 2010 there are some new features introduced.Content Query Web Part (CQWP) is used to show information from sites in the current site collection by querying, filtering, and sorting the content. Also CQWP you can show information from list as well as from publishing pages. But to use CQWP publishing features need to be enabled.

To add a content Query Web Part (CQWP) Click on Edit Page -> From Editing Tools Select Insert -> Web Part -> Select Content Roolup Categories and then Select Content Query WebPart.


Once you add the content Query WebPart you can click on open the tool pane to configure the web part. When you click on this link the Content Query window will open as shown figure below.

 From the Query section you can select to show items from all site in the current site collection or can browse the particular site or subsite or we can select the list as shown below figure.




In the Presentation tab you can Sort items, Give Styles as shown below fig. You can directly select which fields you want to display rather writing any XSLT for this purpose.



There is one new token  [PageQueryString:PARAMETERNAME] is available to handle Query String parameters. You can use this token in the Additional filers section where you can also filter on different conditions. You can see the pics below:




Also in SharePoint 2010 there is another token available: PageFieldValue which is used to filter that matches the value of another field on the same page only. [PageFieldValue:FIELDNAME] is the syntax to use this token.



That's it.

Sunday, February 26, 2012

Passing value from popup window to parent form's TextBox Using JavaScript


Passing values from a popup window back to the parent page is an often asked question. Especially when there is a GridView type control in the popup. In the following example we will be using two forms. The parent form will be parent.aspx and the popup will be popup.aspx. Also note that the parent.aspx form is derived from some MasterPage.

Code is provided both in VB.Net and C#.Net.

--- .aspx of parent form ---

<script type="text/javascript">
function OpenPopup() {
    window.open("popup.aspx","List","scrollbars=no,resizable=no,width=400,height=280");
    return false;
}
</script>
.      
.
.      
<asp:TextBox ID="txtPopupValue" runat="server" Width="327px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Show List" />
--- .vb of parent.aspx if vb.net is the language ---
If Not IsPostBack Then
    Me.Button1.Attributes.Add("onclick", "javascript:return OpenPopup()")
End If
--- .cs of parent.aspx if C#.net is the language ---
if (!IsPostBack) {
    this.Button1.Attributes.Add("onclick", "javascript:return OpenPopup()");
}
 
--- .aspx of popup form ---
<script language="javascript">
function GetRowValue(val)
{
    // hardcoded value used to minimize the code.
    // ControlID can instead be passed as query string to the popup window
    window.opener.document.getElementById("ctl00_ContentPlaceHolder1_TextBox2").value = val;
    window.close();
}
</script>
 
 
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
    <Columns>
        <asp:TemplateField>
            <AlternatingItemTemplate>
                <asp:Button ID="btnSelect" runat="server" Text="Select" />
            </AlternatingItemTemplate>
            <ItemTemplate>
                <asp:Button ID="btnSelect" runat="server" Text="Select" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
 
--- .vb file if vb.net is the language ---

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    If (e.Row.RowType = DataControlRowType.DataRow) Then
        'assuming that the required value column is the second column in gridview
        DirectCast(e.Row.FindControl("btnSelect"), Button).Attributes.Add("onclick", "javascript:GetRowValue('" & e.Row.Cells(1).Text & "')")
    End If
End Sub
 
--- .cs file if C#.net is the language ---

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {
    if ((e.Row.RowType == DataControlRowType.DataRow)) {
        //assuming that the required value column is the second column in gridview
        ((Button)e.Row.FindControl("btnSelect")).Attributes.Add("onclick", "javascript:GetRowValue('" + e.Row.Cells[1].Text + "')");
    }
}

To Prevent Browser BACK button click after SignOut Using JavaScript


There are so many threads open related to this issue.
After sign out when the user press BACK button on the browser, it gets him to the members page.
Logicaly, it's done on the client side and we cannot do much from the code-behind. So, in order to prevent Browser BACK button click after SignOut, we have to use some javascript.
The first and easiest approach to acomplish this is by using the following javascript code:
<body onload="javascript:window.history.forward(1);">
 This code should be placed on the <body> tag of the Members page where Log out button appears.
The problem is that this code will work perfectly on IE (Internet Explorer) but won't work at all for Mozilla Firefox 3.x versions.
So, in order to make this work on Mozilla Firefox, I've prepared Javascript function which is:
<script type="text/javascript" language="javascript"> 
function disableBackButton()
{
window.history.forward()
}
disableBackButton();
window.onload=disableBackButton();
window.onpageshow=function(evt) { if(evt.persisted) disableBackButton() }
window.onunload=function() { void(0) }
</script>

then call noBack() function on <body> on the following way:

<body onload="noBack();">
 
This code will not let the user get BACK after Sign out.

Dispaly the time on Webpage using Java Script


JavaScript sample to continuously display the current time on the web page. Continuously means that the textbox value will be updated with the current time every second.

<script type="text/javascript">
    function ShowTime() {
        var dt = new Date();
        document.getElementById("<%= TextBox1.ClientID %>").value = dt.toLocaleTimeString();
        window.setTimeout("ShowTime()", 1000);
    }  
</script> 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
<script type="text/javascript">
    // a startup script to put everything in motion
    window.setTimeout("ShowTime()", 1000);
</script>

If you are using normal web form then it can also be called on Body onload event. If you are using MasterPage then it can be called within ContentTemplate at the end after all the controls have been rendered.

Select and Deselect All check boxes in a Grid Using JavaScript

Call the below function in the onclick event of the header check box.

function SelectDeselect(headerCheckBox) {

//Get grid view object using grid view id.

var gridViewControl = document.getElementById('<%=GridView1.ClientID %>');

//Get all input tags from the grid view(i.e table).

var inputTagsFromGrid = gridViewControl.getElementsByTagName("input");

//Loop through each input tag and check the type and select or deselect the input field.

for (index = 0; index < inputTagsFromGrid.length; index++) {

//Checking the type as check box or not.

if (inputTagsFromGrid[index].type == 'checkbox') {

//This will be selected or deselected based on the header checkbox selection.

inputTagsFromGrid[index].checked = headerCheckBox.checked;

}

}
}

Enabling anonymous access in SharePoint 2007


Even though Microsoft has done a great job on improving the user interface in SharePoint 2007, some things are still buried and require a little “black magic” to get done. In this entry I’ll show you how to enable anonymous access on your site.
First, you need to enable anonymous on the IIS web site (called a Web Application in SharePoint land). This can be done by:
•Launching Internet Information Services Manager from the Start -> Administration Tools menu
•Select the web site, right click and select Properties
•Click on the Directory Security tab
•Click on Edit in the Authentication and access control section
Instead we’ll do it SharePoint style using the Central Administration section:
•First get to your portal. Then under “My Links” look for “Central Administration” and select it.
•In the Central Administration site select “Application Management” either in the Quick Launch or across the top tabs
•Select “Authentication Providers” in the “Application Security” section
•Click on the “Default” zone (or whatever zone you want to enable anonymous access for)
•Under “Anonymous Access” click the check box to enable it and click “Save”
NOTE: Make sure the “Web Application” in the menu at the top right is your portal/site and not the admin site.
You can confirm that anonymous access is enabled by going back into the IIS console and checking the Directory Security properties.
Now the second part is to enable anonymous access in the site.
•Return to your sites home page and navigate to the site settings page. In MOSS, this is under Site Actions – Site Settings – Modify All Site Settings. In WSS it’s under Site Actions – Site Settings.
•Under the “Users and Permissions” section click on “Advanced permissions”
•On the “Settings” drop down menu (on the toolbar) select “Anonymous Access”
•Select the option you want anonymous users to have (full access or documents and lists only)
Now users without logging in will get whatever option you allowed them.
A couple of notes about anonymous access:
•You will need to set up the 2nd part for all sites unless you have permission inheritance turned on
•If you don’t see the “Anonymous Access” menu option in the “Settings” menu, it might not be turned on in Central Admin/IIS. You can manually navigate to “_layouts/setanon.aspx” if you want, but the options will be grayed out if it hasn’t been enabled in IIS
•You must do both setups to enable anonymous access for users, one in IIS and the other in each site

Set Focus Controls - AutoPostBack = true Using Java Script

Every time user’s complaints me about page scroll issues. 
For example: If a lengthy page having a dropdown list with AutoPostBack = true at bottom of page. After the selection page gets reloaded and focus will be on top of the page. User needs to again scroll down the page for next key in. Here a sample solution for help... 
c#
public void SetFocus(Page sPage)
    {
        string[] sCtrl = null;
        string sCtrlId = null;
        Control sCtrlFound = default(Control);
        string sCtrlClientId = null;
        string sScript = null;
        sCtrl = sPage.Request.Form.GetValues("__EVENTTARGET");
        if ((sCtrl != null))
        {
            sCtrlId = sCtrl[0];
            sCtrlFound = sPage.FindControl(sCtrlId);
            if ((sCtrlFound != null))
            {
                sCtrlClientId = sCtrlFound.ClientID;
 sScript = "<SCRIPT language='javascript'>document.getElementById('" + sCtrlClientId + "').focus(); if (document.getElementById('" + sCtrlClientId + "').scrollIntoView(false)) {document.getElementById('" + sCtrlClientId + "').scrollIntoView(true)} </SCRIPT>";
 sPage.ClientScript.RegisterStartupScript(typeof(string), "controlFocus", sScript);
            }
        }
    }
Call this function on page load
Example: SetFocus(this);

Redirect to a new page, when we get 404.htm error page in the application



Create a custom Page Not Found is to create a site level feature receiver that will attach it to the webApplication instance.
On the activated event you would attach it like this:
    [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
      if (properties != null)
      {
        try
        {
          SPSite site = properties.Feature.Parent as SPSite;
          System.Uri webApplicationUri = new Uri(site.Url);
          SPWebApplication webApplication = SPWebApplication.Lookup(webApplicationUri);
          if (webApplication != null)
            webApplication.FileNotFoundPage = "CustomError.html";
        }
        catch (Exception ex)
        {
         throw;
        }
      }
   }
And in your deactivated event you could unattach it by setting the same webApplication.FileNotFoundPage to null.
You will also have to save your Custom Page Not found page in the Layout.

Monday, February 13, 2012

Sharepoint Programming Part7

Q) Retrieving information from linked lists in SharePoint using LINQ to SharePoint?

using System.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Linq;


In the Page_Load method, add the following code:


DataContext dc = new DataContext(SPContext.Current.Web.Url);
var customers = dc.GetList < Customer > (“Customers”);
var customerDataSource = from customer in customers
select new {CustomerName = customer.Title,
ContactLastName = customer.PrimaryContact.Title,
ContactFirstName = customer.PrimaryContact.
FirstName};
CustomerGridView.DataSource = customerDataSource;
CustomerGridView.DataBind()


Q)How you can retrieve the name of each folder in the top - level site of a site collection, as well as the number of subfolders that each folder contains?



using System;
using System.Text;
using Microsoft.SharePoint;
namespace Wrox.SixInOne
{
class Program
{
static void Main(string[] args)
{
StringBuilder folderName = new StringBuilder();
using (SPSite site = new SPSite(“http://intranet/”))
{
using (SPWeb web = site.RootWeb)
{
foreach (SPFolder folder in web.Folders)
{
folderName.Append(folder.Name);
folderName.Append(“ “);
folderName.Append(folder.SubFolders.Count);
folderName.Append(“ < br > ”);
}
}
}
}
}
}
Creating a New SPSite Object (SitesAndWebs.cs)
using (SPSite intranetSiteCollection = new SPSite(“http://intranet/”))
{
SPWebCollection websCollection = siteCollection.AllWebs;
foreach (SPWeb web in websCollection)
{
Console.WriteLine(web.Title);
web.Dispose();
}
Console.Read();
}


//Deletes a site collection used for testing
using (SPSite siteCollection = new Site(“http://intranet/sites/test”))
{
siteCollection.Delete();
}
//Deletes a site in the current site collection
using (SPWeb testSite = SPContext.Current.Site.OpenWeb(“test”))
{
testSite.Delete();
}
//Deletes a list called “Invoices” in the current site
SPContext.Current.Web.Lists[“Invoices”].Delete();


//Deletes a list item with a title of “My List Item”
SPList myList = SPContext.Current.


Q)You could use the SharePoint server object model to create a new Yes/No column,
like this:
using (SPSite siteCollection = new SPSite(“http://intranet/”))
{
SPWeb rootWeb = siteCollection.RootWeb;
rootWeb.Fields.Add(“New Field”, SPFieldType.Boolean, true);
}


Q)Sharepoint provides two query objects that use CAML queries. These are SPQuery and
SPSiteDataQuery . SPQuery can query only a single list whereas SPSiteDataQuery can be used to
query data throughout a site collection. Both objects have a Query property that accepts CAML
query text as a string value.
You can create an SPQuery object and pass it in as a parameter to the SPList.GetItems() method
to retrieve all the items (sorted and grouped as you ’ ve specifi ed) that meet the appropriate criteria
in the list. The following example shows a query that returns all the list items from a list where the
Title column value starts with the word “ Policy. ”
string camlQueryText =
“ < Where > < BeginsWith > < FieldRef Name=’Title’/ > ” +
“ < Value Type=’Text’ > Policy < /Value > < /BeginsWith > < /Where > ”;
SPQuery camlQuery = new SPQuery();
camlQuery.Query = camlQueryText;
SPListItemCollection items = list.GetItems(camlQuery);
The SPSiteDataQuery object works in a similar way, except you can use it to retrieve list items
from multiple lists. You can choose either to retrieve items from just one site, or to retrieve
items from that site and any child sites.
Both query objects also provide you with the ability to specify which fi elds you would like returned
as well as a limit to the number of items you want returned.




One of the most compelling reasons for using LINQ to SharePoint instead of CAML is that LINQ
provides strongly typed classes, whereas CAML is written as a string of text that will be executed onlyat runtime. Visual Studio ’ s IntelliSense will help you program against your lists and their columns in
an easy manner, and will alert you at compile time if you are referencing a list or column incorrectly.
In addition to being easier to write, LINQ provides a more readable syntax than CAML.

How to Send Email to Registered Users


 I need to send an email to registered user for every 3 days.Mail starting date will be read from database(sqlserver).This should be done automatically.
I am hosting my website on shared webserver like india.com.
Think I cannot write windows service and install.
I think we need to wrtie webservice which fires acynchronously which checks date.
am n confusion.please guide me.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Configuration;
using System.Data;
using System.Web.Security;


namespace IATI_Email_Application
{
   public partial class ATIEmail : System.Web.UI.Page
   {
       protected void SUBMIT_Click(object sender, EventArgs e)
       {
           String SMTPServerName =
ConfigurationManager.AppSettings["SMTP_SERVER"].ToString();
           String MailUserName =
ConfigurationManager.AppSettings["EMAIL_USERNAME"].ToString();
           String MailPassword =
ConfigurationManager.AppSettings["EMAIL_PASSWORD"].ToString();
           String adminToEmail =
ConfigurationManager.AppSettings["ADMINISTRATOR_TO_EMAIL"].ToString();
           String adminDisplayName =
ConfigurationManager.AppSettings["ADMIN_DISPLAY_NAME"].ToString();
           String subject =
ConfigurationManager.AppSettings["SUBMIT_SUBJECT"].ToString();
           string adminFromEmail =
ConfigurationManager.AppSettings["ADMINISTRATOR_FROM_EMAIL"].ToString();
           String successMessage =
ConfigurationManager.AppSettings["SUBMIT_MAIL_SUCCESS"].ToString();
           String failureMessage =
ConfigurationManager.AppSettings["SUBMIT_MAIL_FAILED"].ToString();
           try
           {
               String FilePath = String.Empty;
               if (FileUpload1.HasFile)
               {
                   try
                   {
                       string filename = FileUpload1.FileName;
                       string filename1 = filename.Substring(0,
filename.LastIndexOf("."));
                       string ext =
filename.Substring(filename.LastIndexOf(".") + 1);
                       filename = filename1 +
Guid.NewGuid().ToString() + "." + ext;
                       FilePath =
Server.MapPath("~/EmailAttachments/") + filename;
                       FileUpload1.SaveAs(FilePath);
                       StatusLabel.Text = "Upload status  File uploaded";
                   }


                   catch (Exception ex)
                   {
                       StatusLabel.Text = "Upload status  The file
could not be uploaded. The following error occured: " + ex.Message;
                   }
               }
               NetworkCredential basicAuthenticationInfo = new
NetworkCredential(MailUserName, MailPassword);
               MailMessage mail = new MailMessage();
               SmtpClient SmtpServer = new SmtpClient(SMTPServerName);
               mail.From = new MailAddress(adminFromEmail, adminDisplayName);
               mail.Subject = subject;
               mail.To.Add(new MailAddress(txtEmail.Text));
               if (FilePath != String.Empty)
               {
                   mail.Attachments.Add(new Attachment(FilePath));
               }
               String mailBody =
System.IO.File.ReadAllText(ConfigurationManager.AppSettings["SUBMIT_TEMPLATE_PATH"].ToString());
               mail.Body = mailBody;
               mail.IsBodyHtml = true;
               mail.DeliveryNotificationOptions =
DeliveryNotificationOptions.OnFailure;
               SmtpServer.Credentials = basicAuthenticationInfo;
               SmtpServer.UseDefaultCredentials = false;
               SmtpServer.Send(mail);
               ClientScript.RegisterStartupScript(this.GetType(),
"myalert", "alert('" + successMessage + "');", true);
               txtEmail.Text = "Enter your email address";


           }
           catch (Exception ex)
           {
               string exmsg = ex.Message;
               ClientScript.RegisterStartupScript(this.GetType(),
"myalert", "alert('" + failureMessage + "');", true);
           }
       }


   }
}

Insert Data Into Sharepoint List Using C# Code


using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;


using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;


namespace insertdataintocustomlist
{
    [Guid("8470d1da-6e24-479c-b0e8-102f82a41a68")]
    public class insertdatademo : System.Web.UI.WebControls.WebParts.WebPart
    {


        public TextBox oTextTitle;
        public TextBox oTextEmployeeName;
      //public TextBox oTextEmployeeID;
        public TextBox oTextEmployeeLocation;
        public TextBox oTextEmployeeDesignation;
        public TextBox oTextEmployeeDateOfJoin;
        public Label oLabelMessage;
        public Button oButtonSubmit;
        public Calendar my;
        
        
        public insertdatademo()
        {
            my = new Calendar();
          
        }


        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            
            
            oTextTitle = new TextBox();
            this.Controls.Add(oTextTitle);


            oTextEmployeeName = new TextBox();
            this.Controls.Add(oTextEmployeeName);


            oTextEmployeeDesignation = new TextBox();
            this.Controls.Add(oTextEmployeeDesignation);


             oTextEmployeeDateOfJoin = new TextBox();
             my = new Calendar();
             my.DataBind();
             my.SelectionChanged += new EventHandler(my_SelectionChanged);
             this.Controls.Add(oTextEmployeeDateOfJoin);
             this.Controls.Add(my);


            //oTextEmployeeID = new TextBox();
            //this.Controls.Add(oTextEmployeeID);


            oTextEmployeeLocation = new TextBox();
            this.Controls.Add(oTextEmployeeLocation);


            oLabelMessage = new Label();
            this.Controls.Add(oLabelMessage);


            oButtonSubmit = new Button();
            oButtonSubmit.Text = "Submit";
            oButtonSubmit.CssClass = "ms-ButtonHeightWidth";
            this.Controls.Add(oButtonSubmit);


            oButtonSubmit.Click += new EventHandler(oButtonSubmit_Click);




            // TODO: add custom rendering code here.
            //Label label = new Label();
            //label.Text = "Hello World";
            //this.Controls.Add(label);
        }


        void my_SelectionChanged(object sender, EventArgs e)
        {
            string strDate = my.SelectedDate.Year + "-" + my.SelectedDate.Month + "-" + my.SelectedDate.Day;
            oTextEmployeeDateOfJoin.Text = strDate;
        }


        void oButtonSubmit_Click(object sender, EventArgs e)
        {
            if (oTextTitle.Text.Trim() == "" || oTextEmployeeName.Text.Trim() == "" || oTextEmployeeDesignation.Text.Trim() == "" || oTextEmployeeLocation.Text.Trim() == "")
            {
                oLabelMessage.Text = "You must specify a value for this required field";
            }
            else
            {
                try
                    {
                SPSite mySite = SPContext.Current.Site;
                SPWeb myWeb = SPContext.Current.Web;
                myWeb.AllowUnsafeUpdates = true;
                
                DateTime dateTimeValue = new DateTime();
                dateTimeValue = Convert.ToDateTime(oTextEmployeeDateOfJoin.Text);
                //dateTimeValue = my.SelectedDates;
                string strDate = dateTimeValue.Year + "-" + dateTimeValue.Month + "-" + dateTimeValue.Day;


                
                SPList myList = myWeb.Lists["Employee's Register"];
                SPListItem myListItem = myList.Items.Add();
                myListItem["Title"] = oTextTitle.Text.ToString();
                myListItem["Employee Name"] = oTextEmployeeName.Text.ToString();
                myListItem["Employee Designation"] = oTextEmployeeDesignation.Text.ToString();
                myListItem["Employee Location"] = oTextEmployeeLocation.Text.ToString();
                myListItem["Employee DteOfJoin"] = strDate;
             //  myListItem["Employee ID"] = oTextEmployeeID.Text.ToString();


                
                myListItem.Update();
                myWeb.AllowUnsafeUpdates = false;
                oLabelMessage.Text = "Recorded inserted";
                ClearChildControlState = true;
                    }
                    catch(Exception ex)
                {
                    oTextEmployeeDateOfJoin.Text = ex.Message;
                    }
            }
        }
       
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("<table class='ms-toolbar' cellpadding='2' cellspacing='0' border='0' width='100%'><tr><td class='ms-toolbar' width='100%'><span class='ms-formvalidation'>");
            oLabelMessage.RenderControl(writer);


            writer.Write("</span</td><td width='100%' class='ms-toolbar' nowrap><IMG SRC='/_layouts/images/blank.gif' width='1' height='18' alt=''></td><td class='ms-toolbar' nowrap='true'><span style='white-space: nowrap;padding-right: 3px;' class='ms-descriptiontext'><span class='ms-formvalidation'>*</span> indicates a required field</span></td></tr></table>");
            writer.Write("<Table class='ms-formtable' style='margin-top: 8px;' border=0 cellpadding=0 cellspacing=0 width=100%>");


            writer.Write("<TR><TD nowrap='true' valign='top' width='190px' class='ms-formlabel'><H3 class='ms-standardheader'><nobr>Title<span class='ms-formvalidation'> *</span></nobr></H3></TD><TD valign='top' class='ms-formbody' width='400px'><span dir='none'>");
            oTextTitle.RenderControl(writer);
            writer.Write("<br></span></TD></TR>");


            writer.Write("<TR><TD nowrap='true' valign='top' width='190px' class='ms-formlabel'><H3 class='ms-standardheader'><nobr>Employee Name<span class='ms-formvalidation'> *</span></nobr></H3></TD><TD valign='top' class='ms-formbody' width='400px'><span dir='none'>");
            oTextEmployeeName.RenderControl(writer);
            writer.Write("<br></span></TD></TR>");


            writer.Write("<TR><TD nowrap='true' valign='top' width='190px' class='ms-formlabel'><H3 class='ms-standardheader'><nobr>Employee Designation<span class='ms-formvalidation'> *</span></nobr></H3></TD><TD valign='top' class='ms-formbody' width='400px'><span dir='none'>");
            oTextEmployeeDesignation.RenderControl(writer);
            writer.Write("<br></span></TD></TR>");


            writer.Write("<TR><TD nowrap='true' valign='top' width='190px' class='ms-formlabel'><H3 class='ms-standardheader'><nobr>Employee Location<span class='ms-formvalidation'> *</span></nobr></H3></TD><TD valign='top' class='ms-formbody' width='400px'><span dir='none'>");
            oTextEmployeeLocation.RenderControl(writer);
            writer.Write("<br></span></TD></TR>");


            writer.Write("<TR><TD nowrap='true' valign='top' width='190px' class='ms-formlabel'><H3 class='ms-standardheader'><nobr>Employee DateOfJoin<span class='ms-formvalidation'> *</span></nobr></H3></TD><TD valign='top' class='ms-formbody' width='400px'><span dir='none'>");
            oTextEmployeeDateOfJoin.RenderControl(writer);
            my.RenderControl(writer);
            writer.Write("<br></span></TD></TR>");


            /*writer.Write("<TR><TD nowrap='true' valign='top' width='190px' class='ms-formlabel'><H3 class='ms-standardheader'><nobr>Employee ID<span class='ms-formvalidation'> *</span></nobr></H3></TD><TD valign='top' class='ms-formbody' width='400px'><span dir='none'>");
            oTextEmployeeID.RenderControl(writer);
            writer.Write("<br></span></TD></TR>");*/




            writer.Write("<table class='ms-formtoolbar' cellpadding='2' cellspacing='0' border='0' width='100%'><tr><td width='99%' class='ms-toolbar' nowrap><IMG SRC='/_layouts/images/blank.gif' width='1' height='18' alt=''></td><td class='ms-toolbar' nowrap='true'><TABLE cellpadding='0' cellspacing='0' width='100%'><TR><TD align='right' width='100%' nowrap>");
            oButtonSubmit.RenderControl(writer);
            writer.Write("</TD></TR></TABLE></td></tr></table>");
        }






    }
}

Concated the two Sharepoint Lists Using Event handlers




public override void ItemAdding(SPItemEventProperties properties)
        {
            SPListItem sp = properties.ListItem;
            String strg = (String)sp["Order Num"];
            String strng = (String)sp["Order Date"];
            sp["Order Name"] = strg + strng;

         }

or


 public override void ItemAdding(SPItemEventProperties properties)
        {
            if (properties.ListTitle == "orders")
            {
                string str;
                str = properties.AfterProperties["order_x0020_no"].ToString();
                str = str + properties.AfterProperties["order_x0020_date"];
                properties.AfterProperties["ordename"] = str;
            }
       }

Upload the Files in Sharepoint Using C#




public class insertdatademo : System.Web.UI.WebControls.WebParts.WebPart
{
public FileUpload file; 
}


 public insertdatademo()
        {
           
          file=new FileUpload();
        }


protected override void CreateChildControls()
{


file=new FileUpload();
            file.DataBind();
             this.Controls.Add(file);
            oButtonSubmit.Click += new EventHandler(oButtonSubmit_Click);


}


 void oButtonSubmit_Click(object sender, EventArgs e)
{




if(file.HasFile==true)
                {
                    SPAttachmentCollection attach = myListItem.Attachments;
                    String fileName = file.PostedFile.FileName;
                    byte[] textfile = file.FileBytes;
                    attach.Add(fileName, textfile);




                }
}


protected override void Render(HtmlTextWriter writer)
{


writer.Write("<table class='ms-formtoolbar' cellpadding='2' cellspacing='0' border='0' width='100%'><tr><td width='99%' class='ms-toolbar' nowrap><IMG SRC='/_layouts/images/blank.gif' width='1' height='18' alt=''></td><td class='ms-toolbar' nowrap='true'><TABLE cellpadding='0' cellspacing='0' width='100%'><TR><TD align='right' width='100%' nowrap>");
            file.RenderControl(writer);
            writer.Write("</TD></TR></TABLE></td></tr></table>");


}

How to Use TLS with SMTP to Secure Your Email


Many of us Microsoft Exchange Server administrators have learned to ignore a simple fact: Most email is easily read in transit. You've no doubt heard the chestnut that sending SMTP email is equivalent to sending a postcard; anyone who can access the postcard can read its contents (thus leading to fascinating historical artifacts such as the stamp code for concealing amorous messages in plain sight).
How did this insecure transport method come about? The engineers who originally designed SMTP were working from a very different set of assumptions about how email would be used, who would use it, and how the Internet would be operated and maintained.
Various proposals have been offered to update the security of SMTP traffic by changing, extending, or even replacing basic SMTP to provide authentication, nonrepudiation, and confidentiality. However, SMTP deployment worldwide has reached critical mass; it's very unlikely that the protocol itself will be superseded by something more secure. In order to preserve confidentiality and nonrepudiation, then, we need to focus on methods that work within the confines of existing SMTP deployments.
One solution is to encrypt mail on the client so that it's protected before it's ever seen by an SMTP server. That's exactly what S/MIME does. However, S/MIME deployment can be complex. In exchange for its complexity, it gives us end-to-end protection that can include sender authentication, confidentiality, and nonrepudiation. For many sites, though, S/MIME is overkill; it would be great if there were a way to easily enable encryption for message transport only. This level of protection would be enough to prevent eavesdroppers, even those with access to a target network, from reading messages in transit between servers.
As it happens, there is a way to provide exactly this protection. Exchange Server and many other email servers support the use of Transport Layer Security (TLS) encryption along with SMTP. Just as you can use SSL (a close relative of TLS) to protect an HTTP session, you can use TLS with SMTP to provide both confidentiality and authentication for email traffic.
When you configure a server to both offer and accept, but not require, TLS for SMTP, it's known as opportunistic TLS. Exchange 2003 didn't support opportunistic TLS, but Exchange 2007, Exchange 2010, and Microsoft Office 365 all do. In fact, you can enable this protection even if you have only the default set of self-signed certificates, although you'll find that many servers won't accept them. For that reason, it's a good idea to obtain certificates from a commercial CA for use with SMTP.
The setup process for enabling TLS with SMTP is simple: Obtain a suitable certificate, then install it using the Exchange certificate wizard or the Enable-ExchangeCertificate cmdlet. As soon as you've done so, Exchange will start accepting TLS requests, as signaled by the presence of the STARTTLS SMTP verb, as well as sending STARTTLS itself when communicating with other TLS-capable servers.
Because this is such a simple change to make, and because it provides an immediate privacy benefit, I encourage you to do it sooner rather than later. There's no downside.

No comments:

Post a Comment