May 31, 2013
Mar 19, 2013
Nov 26, 2012
Aug 23, 2012
In Asp.net, how do I embed images in an email?
Kalpesh Satasiya
6:58 PM
ahmedabad, asp.net, Email with Embed Image, Embed Image, india, software developer, software development
4 comments
static void EmbedImages()
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");
//set the content
mail.Subject = "This is an email";
//first we create the Plain Text part
AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain");
//then we create the Html part
//to embed images, we need to use the prefix 'cid' in the img src value
//the cid value will map to the Content-Id of a Linked resource.
//thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:companylogo >", null, "text/html");
//create the LinkedResource (embedded image)
LinkedResource logo = new LinkedResource( "c:\\temp\\logo.gif" );
logo.ContentId = "companylogo";
//add the LinkedResource to the appropriate view
htmlView.LinkedResources.Add(logo);
//add the views
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1"); //specify the mail server address
smtp.Send(mail);
}
Aug 8, 2012
How Parse XML Using Regular Expressions in Asp.net with C#
Kalpesh Satasiya
12:55 PM
ahmedabad, asp.net, software developer, software development, XML Parse
1 comment
Hello Friends,
I got good solution for XML element value find from XML string.
Need to just call this function with parameters XML string, XML element name and default value if value not find into XML string.
private String ExtractContentFromXml(String xml, String element, String defaultValue)
{
String RegExpression = String.Format(@"(?<={0}>)[\S\s]*?(?=\<\/{0})", element);
Match ThisMatch = Regex.Match(xml, RegExpression);
if (ThisMatch.Success)
return ThisMatch.Value;
else
return defaultValue;
}
I hope you will enjoy this solution...
Jan 6, 2012
Dec 15, 2011
How to restore database when database was suspect
Kalpesh Satasiya
5:12 PM
ahmedabad, cursor in sql server, software developer, software development, sql server database suspect, suspect database, web developer, web development
3 comments
ALTER DATABASE DataBaseName SET EMERGENCY
DBCC checkdb(DataBaseName)
ALTER DATABASE DataBaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (DataBaseName, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE DataBaseName SET MULTI_USER
Nov 30, 2011
Create Dynamic Excel file using Asp.Net
{
// make sure nothing is in response stream
response.Clear();
response.Charset = "";
// set MIME type to be Excel file.
response.ContentType = "application/ms-excel";
// add a header to response to force download (specifying filename)
response.AddHeader("Content-Disposition", "attachment; filename=\"MyFile.xls\"");
for (int i = 0; i < 10; i++)
{
// Send the data. Tab delimited, with newlines.
response.Write("Col1 \t Col2 \t Col3 \t Col4 \n");
}
// Close response stream.
response.End();
}
Nov 18, 2011
Parent Child Relationship on self table in sqlserver
Kalpesh Satasiya
3:41 PM
ahmedabad, parent child relation ship in sql server, self relation in sql server, software developer, software development, web developer
2 comments
(
EmpID int PRIMARY KEY,
EmpName varchar(30),
MgrID int FOREIGN KEY REFERENCES Emp(EmpID)
)
GO
Insert few record into table
INSERT dbo.Emp SELECT 1, 'President', NULL
INSERT dbo.Emp SELECT 2, 'Vice President', 1
INSERT dbo.Emp SELECT 3, 'CEO', 2
INSERT dbo.Emp SELECT 4, 'CTO', 2
INSERT dbo.Emp SELECT 5, 'Group Project Manager', 4
INSERT dbo.Emp SELECT 6, 'Project Manager 1', 5
INSERT dbo.Emp SELECT 7, 'Project Manager 2', 5
INSERT dbo.Emp SELECT 8, 'Team Leader 1', 6
INSERT dbo.Emp SELECT 9, 'Software Engineer 1', 8
INSERT dbo.Emp SELECT 10, 'Software Engineer 2', 8
INSERT dbo.Emp SELECT 11, 'Test Lead 1', 6
INSERT dbo.Emp SELECT 12, 'Tester 1', 11
INSERT dbo.Emp SELECT 13, 'Tester 2', 11
INSERT dbo.Emp SELECT 14, 'Team Leader 2', 7
INSERT dbo.Emp SELECT 15, 'Software Engineer 3', 14
INSERT dbo.Emp SELECT 16, 'Software Engineer 4', 14
INSERT dbo.Emp SELECT 17, 'Test Lead 2', 7
INSERT dbo.Emp SELECT 18, 'Tester 3', 17
INSERT dbo.Emp SELECT 19, 'Tester 4', 17
INSERT dbo.Emp SELECT 20, 'Tester 5', 17
GO
Create sql function
create FUNCTION [dbo].[ShowHierarchy]
(
@Root bigint
)
RETURNS
@menutable TABLE(EmpName varchar(max),MgrID int,EmpID int)
AS
BEGIN
DECLARE @EmpID int, @EmpName varchar(30),@MgrID int, @rootid bigint
set @rootid =@Root
SELECT @EmpID=EmpID,@EmpName=EmpName,@MgrID=MgrID FROM dbo.Emp WHERE EmpID = @Root
-- SET @EmpName = (SELECT EmpName FROM dbo.Emp WHERE EmpID = @Root)
if(@EmpName is not null)
begin
insert into @menutable select REPLICATE(' ', @@NESTLEVEL * 4) + @EmpName,@MgrID,@EmpID
end
SET @EmpID = (SELECT MIN(EmpID) FROM dbo.Emp WHERE MgrID = @Root)
WHILE @EmpID IS NOT NULL
BEGIN
insert into @menutable select * from dbo.ShowHierarchy(@EmpID)
SET @EmpID = (SELECT MIN(EmpID) FROM dbo.Emp WHERE MgrID = @rootid AND EmpID > @EmpID)
END
return
END
//call this function from where you want
Select * from dbo.ShowHierarchy(0)
Nov 15, 2011
Nov 11, 2011
Sep 22, 2011
How to call server side function using JQuery in Asp.net
Kalpesh Satasiya
3:04 PM
ahmedabad, asp.net, Call server side function using Jquery, jquery, software developer, software development, web developer, web development
No comments
-------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Call server side method using Jquery</title>
<!-- Add the jQuery Reference Library-->
<script src="Script/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('#btnok').click(function() {
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button" />
<span id="status"></span>
</div>
</form>
</body>
</html>
Code Behide file code (Default.aspx.cs)
-----------------------------------------
Sep 3, 2011
Disable Validation Control From JavaScript.
Aug 24, 2011
Sometimes Page load event not firing in asp.net
Kalpesh Satasiya
4:22 PM
ahmedabad, caching page, event not work, india, page load, page load event, software developer, software development, web developer, web development
No comments
The reason for the page executing doesn't affect the page cycle, the Load event always fires when the page is executed.
So, if the Page_Load doesn't run sometimes, it's because the page is cached and doesn't execute on the server. The page can be cached in the browser, in a router somewhere along the way, or on the server using server side page caching.
If you haven't enabled server side page caching for the page, it's cached in the browser or in the network. You can use cache settings to try to elliminate this:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Aug 4, 2011
Excel Data Reader - Read Excel files in .NET (Convert Excel data to DataTable using Asp.Net)
Kalpesh Satasiya
5:56 PM
ahmedabad, convert excel to datatable, import excel file, india, software developer, software development, web developer, web development
No comments
//1. Reading from a binary Excel file ('97-2003 format; *.xls)
IExcelDataReader excelReader =ExcelReaderFactory.CreateBinaryReader(stream);
//... //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
//... //4. DataSet - Create column names from first row
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
//5. Data Reader methods
while (excelReader.Read()) { //excelReader.GetInt32(0); }
//6. Free resources (IExcelDataReader is IDisposable) excelReader.Close();
I hope help to you.
Jul 12, 2011
Get Physical Path using Asp.Net
Kalpesh Satasiya
5:35 PM
ahmedabad, asp.net, get physical path, india, physical path, software developer, software development, web designing
No comments
Jul 7, 2011
India Currency Format in .Rdcl report and Write custom function in .Rdcl Report.
Kalpesh Satasiya
6:06 PM
.Rdcl report, ahmedabad, custom function in .rdlc report, india, India Currency format, software developer, software development
No comments
Jul 6, 2011
Declare Nested Cursor in Sql Server
Kalpesh Satasiya
5:41 PM
ahmedabad, cursor in sql server, declare nested cursor, india, nested cursor, software developer, software development
1 comment
--Declare outer cursor
fetch next from @inner_cursor into @cartid, @qty while(@@FETCH_STATUS=0)