Tag - C#

Subdomain Mapping in ASP.NET Boilerplate

In AbpTenants table in the database. You can add your custom properties to Tenant class.AbpTenant class defines some basic properties, the most important properties are: TenancyName: This is a unique name of a tenant in the application. It should not be changed normally. It can be used to allocate subdomains to tenants like 'mytenant.mydomain.com'. Tenant.TenancyNameRegex constant defines the...

Using EPPlus library to manage excel spreadsheets in .NET

EPPlus is a library to manage excel spreadsheets, using OOXML. To install EPPlus, you can search for EPPlus in "NuGet Package Manager" or simply run the following command in the "Package Manager Console": PM> Install-Package EPPlus After installing we are going to need to use this namespace: using OfficeOpenXml; I got an exception while reading from an excel...

How to Access controls on Master Pages from Content Pages in ASP .NET

We will assume that we have a Label control called "Label1" on your Master Page, you might want to change the text of that Label.To do that write this code in your content page: Label lbl = new Label(); lbl = (Label)Master.FindControl("Label1"); lbl.Text = "Text"; Of course, this is all assuming the label is OUTSIDE the ContentPlaceHolder

Cross Page Postback in ASP.NET

This is a new feature in ASP .NET 2.0. The IButtonControl Interface contains a new property called PostBackUrl which points to the page to which the current page will postback, Button, ImageButton and LinkButton implements this interface and exposes the cross page postback functionality. When user clicks the button in the current page will postback...

Export to excel in ASP.NET using C#

In this article we are going to show two examples of exporting to excel. First one is how to export grid view control to excel and the second one is how to export data table to excel. 1-Export Grid View control to Excel: HtmlForm htmlForm = new HtmlForm(); string fileName = "attachment; filename=Reports.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", fileName); Response.ContentType = "application/ms-excel"; StringWriter strw...

Send email using C#

We are going to use Gmail outgoing mail server in our code here to demonstrate how you can send an email from your application using C# SmtpClient oSmtpClient = new SmtpClient(); oSmtpClient.Host = "smtp.gmail.com"; //The Outgoing mail server oSmtpClient.Credentials = new NetworkCredential("Your Email", "Your password"); oSmtpClient.Port = 587; oSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; oSmtpClient.EnableSsl = true; MailMessage msg = new MailMessage("Email From", "Email...

Captcha image in C#.NET

What Captcha stand for? Completely Automated Public Turing test to tell Computers and Humans Apart. The Captcha technology help you to make sure your site is reasonably secure against automated attacks. Write the following code in a class named Captcha: public class Captcha { //make the captcha image for text public Bitmap MakeCaptchaImage(string txt, int width, int hight,...

Get the referring page on Page_Load event in ASP.NET

When a page loads, in order to get the name of the page that sent you there, all you need to use is: Request.UrlReferrer.ToString(); You can create a global variable to hold it: string sReferrer = ""; Then, in the Page_Load event, assign it: if (!Page.IsPostback) { sReferrer = Request.UrlReferrer.ToString(); } Or, you can put it in ViewState at...