Monday, April 29, 2013

How to get the Gridview values for the selected row on link button click.

Question:-

I have a link button bound to my gridview. On clicking the link button, I need to fetch the other column values for the selected row in the codebehind. How do get the gridview values for the selected row on link button click?

Answer:-

protected void LinkButton1_Click(object sender, EventArgs e) 
{ 
        LinkButton lb = (LinkButton)sender; 
        GridViewRow row = (GridViewRow)lb.NamingContainer; 
        if (row != null) 
        { 
            int index = row.RowIndex; //gets the row index selected 
            string ID = grd.Rows[index].cells[cellcount].Text;
        } 
}

Reference

http://forums.asp.net/t/1880980.aspx/1

Friday, April 26, 2013

How do I send mail using C# or ASP.NET?

Here is the simple code snippet...

System.Net.Mail.Mailemail email = new System.Net.Mail.Mailemail();
email.To.Add("ToAddress@email.com");
email.Subject = "This is the Subject line";
email.From = new System.Net.Mail.MailAddress("FromAddress@email.com");
email.Body = "This is the email body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("SMTP Host Address");
smtp.Send(email);

Here is the very simple and short code snippet...


System.Web.Mail.SmtpMail.SmtpServer="SMTP Host Address or IP Address";
System.Web.Mail.SmtpMail.Send("from","To","Subject","MessageText");

Fixing: One or more field types are not installed properly. Go to List settings page to delete these fields.


Issue:

Just Now I got this error “One or more field types are not installed properly. Go to List settings page to delete these fields” when trying to access one of the deployed sites after having deployed WSP files in SharePoint 2010.

Solution:


1.  Go to Site Actions, Site Settings and Site Collection features under Site Collection Administration.
2.  Deactivate the SharePoint Server Publishing Infrastructure feature
3.  Go back to http://portalsite/relationships%20list/allitems.aspx
4.  Go to List, List Settings and Delete this list (If the SharePoint Server Publishing Infrastructure feature is not deactivated this option will not be visable)
5.  After deleting the list go back to Site Actions, Site Settings, and Site Collection features
6.  Activate SharePoint Server Publishing Infrastructure feature (Note: If you recieve this error:
Column Limit Exceeded.
There are too many columns of the specified data type. Please delete some other columns first. Note that some column types like numbers and currency use the same data type.
7.  The SharePoint Server Publishing Infrastructure feature will automatically recreate the list.
Go back to http://portalsite/relationship%20list/allitems.aspx and varify that the column GroupGuid now has a column of type GUID instead of text.
Now go back to the site you were trying to access and you should no loger get that error message “One or more field types are not installed properly. Go to List settings page to delete these fields”

Reference: 

Thursday, April 25, 2013

An error occurred during the processing of a configuration file required to service this request

Issue:

An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.


  • Server Error in '/' Application.


    Configuration Error

    Description:An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

    Source Error:

    Line 74:             ASP.NET to identify an incoming user. 
    Line 75:         -->
    Line 76: <authentication mode="Forms" /> Line 77:     <!--
    Line 78:             The <customErrors> section enables configuration 

    Source File: C:\inetpub\vhosts\primetravels.in\httpdocs\admin\web.config Line:76


    Version Information: Microsoft .NET Framework Version:2.0.50727.5420; ASP.NET Version:2.0.50727.5420


Solution:

We have to make sure our virtual directory is configured as an application in IIS.
if you created the web application and try to create the virtual directory for the web site. you will get the above error. Simple resolution is

Go to your IIS--> Click site --> choose the virtual directory site (you have configured)--> then convert to application.  that's it. :)

Note: Please make sure you have admin access to the site and add Network Service role to web site in the permission tab if you use IIS 7 and above.

Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list



Issue:

Just now I got the below issue when i try to browse the new web site deployed in IIS.

HTTP Error 500.21 - Internal Server Error

Handler "WebServiceHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list.

Solution:


To fix this, Simply I ran the following command at the command prompt with Admin rights

If I had been on a 64 bit system, it would have looked like the following:

%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i

If I had been on a 32 bit system, it would have looked like the following:

%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i 


Reference

http://stackoverflow.com/questions/6846544/how-to-fix-handler-pagehandlerfactory-integrated-has-a-bad-module-managedpip

Tuesday, April 23, 2013

Recommendation Service Accounts for SharePoint


Some of the recommendation Service Accounts for SharePoint.
Account name
Role
Domain rights
Local SharePoint Server rights needed
SQL rights needed
sp_install
Used to install SharePoint binaries.
Domain User
Local administrator on all SharePoint boxes
dbcreator and securityadmin SQL roles
sp_farm
Farm account. Used for Windows Timer Service, Central Admin and User Profile service
Domain User
Local Admin during UPS provisioning, log on locally right
None
sp_webapp
App pool id for content web apps
Domain User
None
None
sp_serviceapps
Service app pool id
Domain User
None
None, unless using Office Web Apps. Them must give access to content databases manually
sp_search
Search process id
Domain User
None
None
sp_content 
Account used to crawl content
Domain User
None
None
sp_userprofile1
Account used by the User Profile services to access Active Directory
Must have Replicating Change permissions to AD. Must be given in BOTH ADUC and ADSIEDIT. If domain is Windows 2003 or early, must also be a member of the "Pre-Windows 2000" built-in group.
None
None
sp_superuser2
Cache account
Domain User
Web application Policy Full Control
Web application super account setting
None
sp_superreader2
Cache account
Domain User
Web application Policy Full read
Web application super reader account setting
None

The above table service accounts are just recommendations only. It may vary for multiple application pools and instance. Your particular farm may require different accounts.

Reference


Service Accounts Required for Installation of Team Foundation Server



The service accounts in the following table are the identities for Team Foundation Server and its components.
The service account for Team Foundation Server is also used in Internet Information Services (IIS) as the identity of the application pool for Team Foundation Server.

Component
Sample user logon name 
Requirements
Team Foundation Server
TFSSERVICE
You can specify a built-in account or a user account. If you specify a user account, it must have the Log on as a service permission.
You must not use the account that you use to install Team Foundation Server as the account for TFSSERVICE. For example, if you are logged in as domain\user1 when you install Team Foundation Server, do not use domain\user1 as the account for TFSSERVICE.
If you are using reports, you must add TFSSERVICE to the Content Manager role on the server that is running SQL Server Reporting Services. For more information, see Add the Service Account for Team Foundation Server to the Report Server.
If your SharePoint site was not installed at the same time as Team Foundation Server, you must add TFSSERVICE to the Farm Administrators group for the SharePoint Central Administration site. For more information, see Add the Service Account for Team Foundation Server to the Farm Administrators Group.
Default: Network Service
Team Foundation Build
TFSBUILD
You can specify a built-in account or a user account. If you use a user account, it must have the Log on as a service permission.
Team Foundation Server Proxy
TFSPROXY
You can specify a built-in account or a user account. If you use a user account, it must have the Log on as a service permission.

  

The report reader account is the identity that is used to gather information for reports. If you use reporting, you must specify a report reader account when you install Team Foundation Server.
If you install Team Foundation Server with the default options, the report reader account is also used as the identity of the service account for SharePoint Foundation 2010.

Feature
Sample user logon name
Requirements
Reporting
TFSREPORTS
You must specify a user account that has the Allow log on locally permission.
Default: You are prompted for this account. You cannot use a built-in account for the report reader account.


The following table lists the service accounts that are the identities that are used to run Windows services for SharePoint Products and SQL Server.
The service account for SharePoint Products is also the identity of the application pool for the SharePoint Central Administration site.

Software
Sample user logon name
Requirements
SharePoint Products
WSSSERVICE
You must specify a user account.
Default: If you install Team Foundation Server with the default options, the account that you specified as the report reader account is also used for this account.
SQL Server
SQLSERVICE
You can use a built-in system account or set up an account before you install SQL Server. Team Foundation Server has no requirements for this account.

To make it easier to discuss the different accounts that Team Foundation Server requires, this guide uses the placeholder names that are specified in the tables above. You do not have to use these placeholder names for any accounts that you might create.

Reference



Export User Information from SharePoint Site to Excel


1.       Go to "Site Settings -> Users and Permissions -> People and groups"
2.       Click on the "Settings" menu and "List Settings"
3.       Scroll to the bottom of the page and click on the view that you want to export.
4.       Copy the url and in particular the List and View IDs
http://sitename/_layouts/ViewEdit.aspx?List=%7B64DAB4AC%2DD043%2D4DA4%2D85C7%2D9D4521C3F4CC%7D&View=%7B0FAE8D90%2D59D5%2D48F4%2DA54E%2DF02333777C7F%7D&Source=%252F%255Flayouts%252Flistedit%252Easpx%253FList%253D64dab4ac%252Dd043%252D4da4%252D85c7%252D9d4521c3f4cc%2526Source%253DhttpFlayouts%25252Fpeople%25252Easpx%25253FMembershipGroupId%25253D6
5.       Go to the following url "http://[sitename]/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List=[LISTID]&View=[VIEWID]&CacheControl=1" replacing sitename, listid, and viewid with your own information.
6.       When opening this in the browser you will get a save to excel option and from there you just have to open the file.

Export SharePoint Permissions to Excel


Export SharePoint Permissions to Excel

Just now I had requested from the users asking to Export SharePoint permissions to Excel Sheet. 

Now there is a way to export it from SharePoint.

One of the easiest ways to export SharePoint permission using excel itself. To do this , you will have to Open 

Excel Sheet , Navigate to Data Tab – Click on “From Web”, as shown in the below Screen shot






Once you click on that, it will bring up a New Web Query pop up Box, You will have to enter the URL and 

Select the check boxes Highlighted in yellow to import it in Excel.

 

















Select the desired users, Click on Import. All the users imported. that's it.



Reference

Monday, April 22, 2013

Download and Upload in ASP and C#.NET



Download Code

string filename = "filename from Database";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
string aaa = Server.MapPath("~/SavedFolder/" + filename);
Response.TransmitFile(Server.MapPath("~/SavedFolder/" + filename));
Response.End();

Upload Code

string FilePath = "";
string[] a = new string[1];
string fileName = "";
string FullName = "";
 
if (FileUploader.FileName.Length > 0)
{
     a = FileUploader.FileName.Split('.');
     fileName = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
     FilePath = Server.MapPath(@"~\SavedFolder");
     Fup1.SaveAs(FilePath + @"\" + fileName);
 
     FullName = FilePath + @"\" + fileName;
     // Database Saved Code
}


Reference

http://www.codeproject.com/Tips/185886/File-Upload-and-Download-in-ASP-NET

Print all the data from GridView



 private void PrintAllPages()
        {
            try
            {
                grvUsers.AllowPaging = false;
                grvUsers.DataBind();
                StringWriter sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                grvUsers.RenderControl(hw);
                string gridHTML = sw.ToString().Replace("\"", "'")
                    .Replace(System.Environment.NewLine, "");
                StringBuilder sb = new StringBuilder();
                sb.Append("<script type = 'text/javascript'>");
                sb.Append("window.onload = new function(){");
                sb.Append("var printWin = window.open('', '', 'left=0");
                sb.Append(",top=0,width=1000,height=600,status=0');");
                sb.Append("printWin.document.write(\"");
                sb.Append(gridHTML);
                sb.Append("\");");
                sb.Append("printWin.document.close();");
                sb.Append("printWin.focus();");
                sb.Append("printWin.print();");
                sb.Append("printWin.close();};");
                sb.Append("</script>");
                ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
                grvUsers.AllowPaging = true;
                grvUsers.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

Export To Excel method using C#.NET




Protected void ExportToExcel()
        {
            Response.Clear();
            Response.Buffer = true;

            Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            grvUsers.AllowPaging = false;
            grvUsers.DataBind();

            //Change the Header Row back to white color
            grvUsers.HeaderRow.Style.Add("background-color", "#FFFFFF");

            //Apply style to Individual Cells
            //grvUsers.HeaderRow.Cells[0].Style.Add("background-color", "Green");
            grvUsers.HeaderRow.Cells[0].Style.Add("background-color", "#EF6E16");
            grvUsers.HeaderRow.Cells[1].Style.Add("background-color", "#EF6E16");
            grvUsers.HeaderRow.Cells[2].Style.Add("background-color", "#EF6E16");
            grvUsers.HeaderRow.Cells[3].Style.Add("background-color", "#EF6E16");
            grvUsers.HeaderRow.Cells[4].Style.Add("background-color", "#EF6E16");
            grvUsers.HeaderRow.Cells[5].Style.Add("background-color", "#EF6E16");
            grvUsers.HeaderRow.Cells[6].Style.Add("background-color", "#EF6E16");

            for (int i = 0; i < grvUsers.Rows.Count; i++)
            {
                GridViewRow row = grvUsers.Rows[i];

                //Change Color back to white
                row.BackColor = System.Drawing.Color.White;

                //Apply text style to each Row
                row.Attributes.Add("class", "textmode");

                //Apply style to Individual Cells of Alternating Row
                if (i % 2 != 0)
                {
                    //row.Cells[0].Style.Add("background-color", "#C2D69B");
                    row.Cells[0].Style.Add("background-color", "#62BDBB");
                    row.Cells[1].Style.Add("background-color", "#62BDBB");
                    row.Cells[2].Style.Add("background-color", "#62BDBB");
                    row.Cells[3].Style.Add("background-color", "#62BDBB");
                    row.Cells[4].Style.Add("background-color", "#62BDBB");
                    row.Cells[5].Style.Add("background-color", "#62BDBB");
                    row.Cells[6].Style.Add("background-color", "#62BDBB");
                }
            }
            grvUsers.RenderControl(hw);

            //style to format numbers to string
            string style = @"<style> .textmode { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }

Monday, April 15, 2013

The operation could not be completed.Unspecified error in Visual Studio 2010


Error:
I am unable to open CSS files in Visual Studio 2010 after adding to a project.
It shows the following error:
The operation could not be completed. Unspecified error.
Even if I try to edit embedded CSS in a webpage directly, intelligence doesn't appear.








Solution
I was having the same issue just now and found that by going to the Tools -> Extension Manager -> Online Gallery and search for/install the "Web Standards Update for Microsoft Visual Studio 2010 sp1" I was able to open CSS files again.

And it worked for me.

Reference

Friday, April 12, 2013

Fix the Crystal Report Viewer Issue



Problem

If this fails to load the Active X control into the clients browser (and this maybe because the customer has a security policy in place that means only admins can download the control) please see instructions for manually installing the crystal reports viewer

Resolution

Manually install the Crystal Reports Viewer in a client’s browser

Note: this process does not work if the server is x86 and the client machine is x64 - produces 
module not found and/or different CPU type errors.

Firstly you will need to find the following cab file on the Server on which crystal reports is installed: ActiveXViewer.cab

For Crystal 10 it is installed in C:\Program Files\Common Files\Crystal
Decisions\2.5\crystalreportviewers10\ActiveXControls\ActiveXViewer.cab

For Crystal 11 it is installed in C:\Program Files\Common Files\Business
Objects\3.0\crystalreportviewers11\ActiveXControls\ActiveXViewer.cab

Within the cab files are the following 3 dlls (you can right click on the cab file and explore to see the files within) – you need to copy the following 3 dlls onto the client machine in step 3 below:-

CRVIEWER.DLL
SWEBRS.DLL
SVIEWHLP.DLL

1) Check to see if the following three files exist on the Client Machine

CRVIEWER.DLL
SWEBRS.DLL
SVIEWHLP.DLL

2) If they exist, then un-register the files:

Run cmd.exe as an administrator and for each dll enter the command

Regsvr32 /u pathtofile\filename

3) Copy these three dll files to the client’s windows\system32 directory

CRVIEWER.DLL
SWEBRS.DLL
SVIEWHLP.DLL

4) Register each file.

Run cmd.exe as an administrator and for each dll enter the command
Regsvr32 pathtofile\filename


5) Add web sites to intranet zone and Check Active X settings:-

Note: These instructions are based on Internet Explorer 7 Browsers

Click on Tools >Internet Options
Click on the Security Tab
Select Local Intranet Zone
Click on the Sites Button
In the popup window click on the Advanced Button
In the Box “Add this website to the Zone” enter http://*.mysite.net
Click on the add button
Click on the close button
Click on the OK button
You should now be back at the Security tab

Click on the “custom level” button
Scroll down to the settings for the category “Active X controls”
Ensure that the following are set within this category
Allow previously unused ActiveX controls to run without prompt = Enable
Allow Scriptlets = Enable
Automatic prompting for ActiveX Controls = Enable
Binary and script behaviours = Enable
Display video and animation on a webpage that does not use external media player = Disable
Download signed Active X controls = Prompt
Download unsigned Active X controls = Disable
Initials and script Active X controls not marked as safe for scripting = Disable
Run ActiveX controls and plugins = Enable
Script Active X controls marked as safe for scripting = Enable
Click on OK
Click on OK

6) Try and obtain a report in your web site

In your IE browser login to the your website and try to generate a report
You may be prompted to install the active X control – allow the installation, allow the active X control to run.

That’s it. The report should be displayed.