Archive

Archive for December, 2009

Bind List Names and Column Names of a List in a Site


Get All List and  Column Names in Sharepoint

//Load Lists and Column Names of a List
SPWebCollection subSites = SPContext.Current.Site.AllWebs;

for (int i = 0; i < subSites.Count; i++)
{
SPListCollection lists = subSites[i].Lists;

for (int j = 0; j < lists.Count; j++)
{
ddl.Items.Add(Microsoft.SharePoint.Utilities.SPEncode.HtmlEncode(subSites[i].Title)
+ ” :: ” + subSites[i].Url + ” :: ”
+ Microsoft.SharePoint.Utilities.SPEncode.HtmlEncode(lists[j].Title));
}
}

bool bl = false;
if (ddlURL.Items.Count == 0)
{
ddlURL.Items.Add(“Please Select One Value”);
}
foreach (SPListItem item in SPContext.Current.Web.Lists[“TestFilter”].Items)
{
foreach (SPField field in item.Fields)
{
//ddlURL.Items.Add(field.InternalName + “::” + field.Title + “::” + field.StaticName);
foreach (ListItem lstitem in ddlURL.Items)
{
if (field.Title == lstitem.Text)
{
bl = true;
break;
}
}
if (bl == false)
{
ddlURL.Items.Add(field.Title);
}
}
}
//End

 

Advertisements

Web part Custom Properties


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;

using System.ComponentModel;

using System.Drawing;
namespace WebPartPro
{
[Guid(“5a1f7b2e-7bc4-4040-b942-4188a0a50d98”)]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{

public WebPart1()
{
}

private string _name;
private KnownColor _color = KnownColor.Black;
private double _principal;
private double _rateofinterest;
private double _time;
private double _amount;

[WebBrowsable(true),
Personalizable(PersonalizationScope.User),
WebDescription(“Enter a name”),
Category(“Custom Properties”),
WebDisplayName(“Name to display”)]
public string Name
{
get { return _name; }
set { _name = value; }
}

[WebBrowsable(true),
Personalizable(PersonalizationScope.User),
WebDescription(“Choose a text color”),
Category(“Custom Properties”),
WebDisplayName(“Text Color”)]
public KnownColor MyColor
{
get { return _color; }
set { _color = value; }
}

[WebBrowsable(true),
Personalizable(PersonalizationScope.User),
WebDescription(“Enter the principal amount”),
Category(“Custom Properties”),
WebDisplayName(“Principal Amount”)]
public double Principal
{
get { return _principal; }
set { _principal = value; }
}

[WebBrowsable(true),
Personalizable(PersonalizationScope.User),
WebDescription(“Enter the rate of interest”),
Category(“Custom Properties”),
WebDisplayName(“Rate of Interest”)]
public double RateofInterest
{
get { return _rateofinterest; }
set { _rateofinterest = value; }
}

[WebBrowsable(true),
Personalizable(PersonalizationScope.User),
WebDescription(“Time in years”),
Category(“Custom Properties”),
WebDisplayName(“Time(in Years)”)]
public double Time
{
get { return _time; }
set { _time = value; }
}

public enum Interest
{
SimpleInterest,
CompoundInterest
}

private Interest _interesttype = Interest.SimpleInterest;

[WebBrowsable(true),
Personalizable(PersonalizationScope.User),
WebDescription(“Choose the type of interest to calculate”),
Category(“Custom Properties”),
WebDisplayName(“Type of Interest”)]
public Interest Interesttype
{
get { return _interesttype; }
set { _interesttype = value; }
}

public double Amount
{
get { return _amount; }
set { _amount = value; }
}

protected override void CreateChildControls()
{
base.CreateChildControls();
// TODO: add custom rendering code here.
Label label = new Label();
if (string.IsNullOrEmpty(Name))
{
Name = “Guest!!”;
}

if (Interesttype.ToString().Equals(“SimpleInterest”))
{
Amount = Principal + ((Principal * RateofInterest * Time) / 100);
}
else
{
Amount = 0;
}

label.Text = string.Format(“Hello {0} the amount for your principal {1} with {2} of {3}% for {4} years is {5}”, Name, Principal, Interesttype, RateofInterest, Time, Amount);
label.ForeColor = Color.FromKnownColor(MyColor);
this.Controls.Add(label);
}

}
}

C# Get Set Properties

Categories: Dot Net

Sharepoint List Multiline text Filter web part

December 23, 2009 4 comments

Upload Document to Document library inside folder


public void UploadToMoss(string filename, int fileLength, Stream oStream, stringstrDocLibraryName, string atchType, string strETAID)

{

WindowsIdentity objWindowsIdentity = WindowsIdentity.GetCurrent();

WindowsImpersonationContext objWindowsImpersonationContext = null;

RevertToSelf();

SPSite siteCollection = null;

SPWeb topLevelSite = null;

SPList list = null;

SPFolderCollection folders = null;

SPFolder objFolder = null;

SPWeb test = null;

 

 

 

 

 

 

 

bool blStatus = true;

try

{

SPSecurity.RunWithElevatedPrivileges(delegate()

{

siteCollection = newSPSite(System.Configuration.ConfigurationManager.AppSettings[“SPDocumentLibrary”].ToString());

topLevelSite = siteCollection.AllWebs[ConfigurationManager.AppSettings[“TopLevelSite”].ToString()];

});

topLevelSite.AllowUnsafeUpdates = true;

list = topLevelSite.Lists[System.Configuration.ConfigurationManager.AppSettings[“DocumentLibrary”]];

siteCollection.OpenWeb();

siteCollection.AllowUnsafeUpdates = true;

topLevelSite.AllowUnsafeUpdates = true;

folders = topLevelSite.GetFolder(strDocLibraryName).SubFolders;

folders.Add(strETAID);

objFolder = topLevelSite.GetFolder(strDocLibraryName + “/” + strETAID);

 

 

 

 

 

 

 

byte[] bufDoc = null;

string strFileName = Path.GetFileName(filename);

int nLen = fileLength;

bufDoc = new byte[nLen];

oStream.Read(bufDoc, 0, nLen);

SPFile file = objFolder.Files.Add(strFileName, oStream, true);

file.Update();

 

 

 

bool blExists = doesSPWebCollectionContainName(folders, strETAID);

SPListItemCollection folderColl = list.Folders;

 

if (blExists)

{

SPFileCollection files = topLevelSite.Folders[strDocLibraryName].Files;

SPListItem item = file.Item;

item[“ETAID”] = strETAID;

item[“Attachment Type”] = atchType;

item.Update();

}

}

 

 

 

catch (Exception ex)

{

 

throw ex;

}

 

finally

{

topLevelSite.AllowUnsafeUpdates = false;

siteCollection.AllowUnsafeUpdates = false;

siteCollection.Dispose();

topLevelSite.Dispose();

list = null;

topLevelSite = null;

siteCollection = null;

folders = null;

objFolder = null;

}

}

http://www.infoitweb.com/Common/Articles.aspx?TypeID=11&ContentID=137

Currency Convertion



——————————————————–

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,”);
if(isNaN(num))
num = “0”;
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
———-

————–
onclick=”this.form.input.value=formatCurrency(this.form.input.value);”
onBlur=”this.value=formatCurrency(this.value);”

———

function CreatePO()
{
var btnName=document.getElementById(“Button1″).value;

if(btnName==”Mark PR Complete”)
{
var answer = confirm(“Are you sure you wish to Mark PR Complete?”);
if (answer) return true;
else return false;
}
else
{
var answer = confirm(“Are you sure you wish to create a Purchase Order?”);
if (answer) return true;
else return false;
}
}
——————
ID=”Button1″ runat=”server” Text=”Mark PR Complete” OnClientClick=”javascript: return CreatePO();”
————————————————–

ID=”btn_PR_SAVE” runat=”server” Text=” Save ” CssClass=”button” OnClientClick=”javascript : return confirm(‘Are you sure you wish to save a Purchase Requisition?’);”

ID=”btn_PR_CREATE_PO” runat=”server” Text=”Create PO” CausesValidation=”true”
CssClass=”button” OnClientClick=”if (!confirm(‘Are you sure you wish to create a Purchase Order?’)) return false;”
——————————————————————-
decimal decValue = Convert.ToDecimal(TextBox1.Text);
string k1 = String.Format(“{0:000,000.00}”, decValue);
char[] MyChar = { ‘ ‘, ‘0’ };
k1 = k1.TrimStart(MyChar);
char[] MyChar2 = { ‘ ‘, ‘,’ };
k1 = k1.TrimStart(MyChar2);
TextBox1.Text = k1;
—————————————————————————–

String Splitting
——————–
Input
strEmployeeName=”John K(johnk)”;

public string[] SplitEmployeeNameFQN(string strEmployeeName)
{
string[] strInputValue = strEmployeeName.Split(‘;’);
string[] arrReturn = new string[2];
//string employeeName = string.Empty;
string strFQN = string.Empty;
for (int i = 0; i < strInputValue.Length; i++)
{
if (!(strInputValue[i] == ""))
{
int startIndex = strInputValue[i].IndexOf("(");
strFQN = strInputValue[i].Substring(startIndex + 1);
strFQN = strFQN.Replace(")", "");
arrReturn[0] += strFQN.Trim() + ";";
arrReturn[1] += strInputValue[i].Remove(startIndex).Trim() + ";";
}
}

return arrReturn;
}
Optput: arrReturn[0]=”John K”;
arrReturn[1]=” johnk”;

—————————
lbl_PR_WBSTotalBudget.Text = lbl_PR_WBSTotalBudget.Text.Replace(“,”, “”);
lbl_PR_WBSTotalBudget.Text = string.Format(“{0:0,0.00}”, Convert.ToDecimal(lbl_PR_WBSTotalBudget.Text));

Categories: ASP.NET, Dot Net

GridView Radio Button Control


grdvwProjectNumber.DataSource = AccountingProject;
grdvwProjectNumber.DataBind();
FindChieldControls()
————————————————————
protected void FindChieldControls()
{
try
{
foreach (GridViewRow rowOne in grdvwProjectNumber.Rows)
{
string strParentProjID = string.Empty;
string strProjID = string.Empty;
Label lblProjectID = (Label)rowOne.FindControl(“lblProjectID”);
strProjID = lblProjectID.Text;
int intCount;
intCount = 0;
foreach (GridViewRow row in grdvwProjectNumber.Rows)
{
Label lblParentProjectID = (Label)row.FindControl(“lblParentProjectID”);
strParentProjID = lblParentProjectID.Text;
if (strParentProjID == strProjID)
{
intCount = intCount + 1;
break;
}
}
if (intCount != 0)
{
grdvwProjectNumber.Rows[rowOne.RowIndex].Cells[6].Controls.Clear();
}
}
}
catch (Exception ex)
{
GenericExceptionMethod(ex);
}
}

Categories: ASP.NET, Dot Net