2009/11/04

Export dataGrid to excel

if you need to export dataGrid to excel sheet you can do it as the following.
1- get dataGrid object with data.
2- create object of HtmlTextWriter.
3- try to write the Grid using HtmlTextWriter in you response.

as the following in button_Click event of any other location you want to perform this action.

string attachment = "attachment; filename=RegisteredUsers.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "UTF-8";
Response.ContentType = "application/vnd.ms-excel";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
GridView grd = new GridView();
grd.DataSource = EntityDataSource1;
grd.DataBind();

grd.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();

Changing machine name Problem in sharepoint

When I tried to change the machine name while I already have sharepoint server installed on this machine with many publishing webApplications, the problem is central administration and sharepoint websites can't load.
So, you can do it as the following.

1- change the machine name from computer settings to the name you want.
2- open RUN
3- goto the destination of stsadm (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN)
4- Now you can run the following command line
stsadm -o renameserver -oldservername -newservername .

5- The last step is to open centeral administration and change the servername from the URL to (localhost). goto to Operation Tab, choose alternative mapping access and change the machine name at all mapping URLs to your new one.