We are MOVING!!!

Thanks for visit, but we are moving to new website.

Please see https://blog.freezeq.com to see more articles.

Advertisements

jQuery event conflicts with ASP.NET Update Panel

There is a problem when I attached click event to ASP page inside Update Panel control.
I put click event onto a button using jQuery.

$("#btn").click(function () {
	alert("clicking button");
});

After asynchronous load is triggered by update panel, clicking that button will not show any alert anymore.
Seems click event are detached.
The fact is any event control which put using client side or jQuery will failed inside update panel. Why?

Continue reading

SharePoint – Custom Sign Out page

Developing Form Base Authentication (FBA) for Sharepoint project sometimes need big struggle, besides developing OOTB Sharepoint itself. After created custom login, I found new problem when tried to sign out from default link. It will show error page / internal server error. Caused by default page is not working properly, it signed out but doesn’t remove cookies from browser. So what I did is creating new application page, put method to clear cookies, then add a link inside default page which redirect to sign-out page.
Continue reading

Where is Sharepoint Logs ??

One day I worked for remote to Sharepoint Server and did deployment. For short a while, I already installed the solution and site was ready. Time to did some test. Then teeeeeeet.. I got some errors. Then opened windows explorer to see log files. You know, sharepoint logfiles is easy to find on this path:
– SP2007 : “c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS”
– SP2010 : “c:\Program Files\Common Files\Microsoft Shared\web server extensions\14\LOGS”
– SP2013 : “c:\Program Files\Common Files\Microsoft Shared\web server extensions\15\LOGS”
notice that each version of Sharepoint is signed by number 12/14/15.

Continue reading

Sending email for SharePoint, with/without attachment

One of great things we can do with Sharepoint is sending an email. The most easiest way is using SPUtility. This will work if you have set up Outgoing email in Central Admin.
outgoing email

private void SendEmail()
{
	// Build the email message headers
	StringDictionary headers = new StringDictionary();
	headers.Add("to", "user@email.com");
	headers.Add("subject", "Item Records");	
	headers.Add("content-type", "text/html");
	
	// Send the email
	SPSecurity.RunWithElevatedPrivileges(delegate()
	{
		using (var elevatedSite = new SPSite(SPContext.Current.Site.ID))
		{
			using (var elevatedWeb = elevatedSite.OpenWeb())
			{
				SPUtility.SendEmail(elevatedWeb, headers, GetEmailBody());
			}
		}
	});
}

private String GetEmailBody()
{
	StringBuilder sb = new StringBuilder();
	sb.Append(String.Format("<p>Below is the {1} records on {0:dd MMM yyyy HH:mm}.</p>", DateTime.Now, "Item List"));
	
	return sb.ToString();
}

Continue reading

Export/Import CSV file from/to listitem Sharepoint

We are able to export items from Sharepoint list into CSV files (comma-separated-values) and do opposite too, import csv into Sharepoint list.

Export : using codes below, you will get csv as download-file. Prepare a list inside your site, named it “Item List”, with 3 columns : Title, Price, Description.

private void ExportToCsv()
{
	Response.Clear();
	Response.Buffer = true;
	Response.AddHeader("content-disposition", "attachment;filename=Itemrecord.csv");
	Response.Charset = "";
	Response.ContentType = "application/text";
		
	// get data
	DataTable dtItem = GetDataFromList();
	StringBuilder sb = new StringBuilder();
	if(dtItem != null)
	{
		// separate each column with comma
		foreach (DataColumn dc in dtItem.Columns)
		{
			sb.Append(dc.ColumnName + ',');
		}
		
		// newline for value
		sb.AppendLine();
		
		// get value
		foreach (DataRow dr in dtItem.Rows)
		{
			foreach (DataColumn dc in dtItem.Columns)
			{
				sb.Append(dr[dc.ColumnName].ToString() + ',');
			}
			sb.AppendLine();
		}
		
		Reponse.Output.Write(sb.ToString());
		Response.Flush();
		Response.End();
	}
}

private DataTable GetDataFromList()
{
	// I have a list 'Item List' with 3columns
	SPQuery query = new SPQuery();
	query.ViewFields = "<FieldRef Name='Title' />
						<FieldRef Name='Price' />
						<FieldRef Name='Description' />";
	SPList list = SPContext.Current.Site.RootWeb.Lists.TryGetList("Item List");
	SPListItemCollection itemColl = list.GetItems(query);
	
	return itemColl.GetDataTable();
}

As result, you will get file “Itemrecord.csv”, contains firstline as column name, nextline as values.

Continue reading

Click Event on Row Gridview

Recent days, I got requirement to make gridview clickable and click event has to redirect user to Edit page. After few googling, I found a simple way to do it. Actually I did this for SPGridview (Sharepoint) and it’s also work for ASP gridview. I’ll try to expose the different of them in next post later.

<SharePoint:SPGridView ID="gridView" runat="server" OnRowDataBound="gridView_RowDataBound" OnSelectedIndexChanged="gridView_SelectedIndexChanged" DataKeyNames="ID" >

Continue reading