using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Mail;
namespace Mail
{
public class SendMail
{
public void Mail(string strFrom,string strTo,string strBody,string strSubject)
{
MailMessage objMailmsg = new MailMessage();
objMailmsg.To = strTo;
objMailmsg.From = strFrom;
objMailmsg.BodyFormat = MailFormat.Html;
objMailmsg.Subject = strSubject;
objMailmsg.Body = strBody;
SmtpMail.SmtpServer = "";
SmtpMail.Send(objMailmsg);
}
}
}
Monday, November 10, 2008
Transfering file from server to client.
Below code will give user option to
* User can download the file from the server and save it by choosing the save option.
* User can open the file.
* User can cancel the all operation.
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
///
/// Summary description for TransmitFile
///
public class TransmitFile
{
public TransmitFile()
{
}
FileDownloadHelper objFileDownloadHelper = new FileDownloadHelper();
public void Transmit(string filePath,string FileName,string FileID)
{
FileInfo myfile = new FileInfo(filePath);
if (myfile.Exists)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + "(" + FileID + ").doc");
HttpContext.Current.Response.AddHeader("Content-Length", myfile.Length.ToString());
HttpContext.Current.Response.ContentType = objFileDownloadHelper.ReturnExtension(myfile.Extension.ToLower());
HttpContext.Current.Response.TransmitFile(myfile.FullName);
HttpContext.Current.Response.End();
}
}
}
* User can download the file from the server and save it by choosing the save option.
* User can open the file.
* User can cancel the all operation.
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
///
/// Summary description for TransmitFile
///
public class TransmitFile
{
public TransmitFile()
{
}
FileDownloadHelper objFileDownloadHelper = new FileDownloadHelper();
public void Transmit(string filePath,string FileName,string FileID)
{
FileInfo myfile = new FileInfo(filePath);
if (myfile.Exists)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + "(" + FileID + ").doc");
HttpContext.Current.Response.AddHeader("Content-Length", myfile.Length.ToString());
HttpContext.Current.Response.ContentType = objFileDownloadHelper.ReturnExtension(myfile.Extension.ToLower());
HttpContext.Current.Response.TransmitFile(myfile.FullName);
HttpContext.Current.Response.End();
}
}
}
Handling Special Case Like & and > while Genrating Xml
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
namespace Utility
{
class GenrateXML
{
public static string Genrate(string Screen, NameValueCollection nvCollection)
{
StringBuilder strXML=new StringBuilder();
strXML.Append("");
strXML.Append("<");
strXML.Append(Screen);
strXML.Append(">");
for (int i = 0; i < nvCollection.Count; i++)
{
strXML.Append("<");
strXML.Append(nvCollection.GetKey(i));
strXML.Append(">");
string strValue = nvCollection.Get(i).Replace("&", "&");
strValue = strValue.Replace("<", "<");
strValue = strValue.Replace(">", ">");
strXML.Append(strValue);
strXML.Append("");
strXML.Append(nvCollection.GetKey(i));
strXML.Append(">");
}
strXML.Append("");
strXML.Append(Screen);
strXML.Append(">");
strXML.Append(" ");
//strXML.Replace("&", "&");
return strXML.ToString();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
namespace Utility
{
class GenrateXML
{
public static string Genrate(string Screen, NameValueCollection nvCollection)
{
StringBuilder strXML=new StringBuilder();
strXML.Append("
strXML.Append("<");
strXML.Append(Screen);
strXML.Append(">");
for (int i = 0; i < nvCollection.Count; i++)
{
strXML.Append("<");
strXML.Append(nvCollection.GetKey(i));
strXML.Append(">");
string strValue = nvCollection.Get(i).Replace("&", "&");
strValue = strValue.Replace("<", "<");
strValue = strValue.Replace(">", ">");
strXML.Append(strValue);
strXML.Append("");
strXML.Append(nvCollection.GetKey(i));
strXML.Append(">");
}
strXML.Append("");
strXML.Append(Screen);
strXML.Append(">");
strXML.Append("
//strXML.Replace("&", "&");
return strXML.ToString();
}
}
}
Setting the focus on Open form.
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Regularex-pressions;
using System.Windows.Forms;
namespace Utility
{
class Validations
{
//Open Form
public static void OpenForm(Form objForm,MDIMainForm _MAIN)
{
bool isOpened = false;
for (int I = 0; I < Application.OpenForms.Count; I++)
{
if (objForm.GetType().Equals(Application.OpenForms[I].GetType()))
{
isOpened = true;
Application.OpenForms[I].Focus();
objForm = null;
break;
}
}
if (!(isOpened))
{
objForm.MdiParent = _MAIN;
objForm.Show();
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Text.Regularex-pressions;
using System.Windows.Forms;
namespace Utility
{
class Validations
{
//Open Form
public static void OpenForm(Form objForm,MDIMainForm _MAIN)
{
bool isOpened = false;
for (int I = 0; I < Application.OpenForms.Count; I++)
{
if (objForm.GetType().Equals(Application.OpenForms[I].GetType()))
{
isOpened = true;
Application.OpenForms[I].Focus();
objForm = null;
break;
}
}
if (!(isOpened))
{
objForm.MdiParent = _MAIN;
objForm.Show();
}
}
}
}
Thursday, August 21, 2008
Execute sql query with exec or execute and Passing Comma Seprated List of IDs to Store Procedure
Hi,
I was in need to create the query in string variable and execute the same.I found the solution which fits in my situation.
The below mentioned way gives you idea where i need that.As i have the list of values and i want only those records to be retrive from the Database.
EXECUTE(@STRQRY)
ALTER procedure [dbo].[spGetData]
@strDataIDs varchar(max)
as
begin
DECLARE @STRQRY NVARCHAR(MAX)
SET @STRQRY= 'select * from DataMaster where accnum not in (' +@strDataIDs+ ')'
EXECUTE(@STRQRY)
end
I was in need to create the query in string variable and execute the same.I found the solution which fits in my situation.
The below mentioned way gives you idea where i need that.As i have the list of values and i want only those records to be retrive from the Database.
EXECUTE(@STRQRY)
ALTER procedure [dbo].[spGetData]
@strDataIDs varchar(max)
as
begin
DECLARE @STRQRY NVARCHAR(MAX)
SET @STRQRY= 'select * from DataMaster where accnum not in (' +@strDataIDs+ ')'
EXECUTE(@STRQRY)
end
Passing Array to Store Procedure in SQL
Passing the array as SQL Parameter is always a concern becuase running the ExceuteQuery for multiple Insert is not a good option through .NET gives you the Implementation of Transaction but this will only serve concurrency issue but somewhere er have to face the performance issue because of this.
So, the need to pass the array to Store Procedure is very comman and the best approch to do this is pass the xml to the Store Procedure in ntext variable.
Create procedure [dbo].[spSendXML]
(
@RecordXML ntext
)
AS
Begin
create Table #tbl (ID int)
DECLARE @idoc int
EXEC sp_xml_preparedocument @idoc OUTPUT, @RecordXML
insert into #tbl
select ID
FROM OPENXML(@idoc,'/Root/Comp', 1)
WITH (ID varchar(50))
End
By doing this you can get all the data in SQL Temp Table.
Calling of the same Store Procedure.
spSendXML ' '
Thanks
Dalip Vohra
So, the need to pass the array to Store Procedure is very comman and the best approch to do this is pass the xml to the Store Procedure in ntext variable.
Create procedure [dbo].[spSendXML]
(
@RecordXML ntext
)
AS
Begin
create Table #tbl (ID int)
DECLARE @idoc int
EXEC sp_xml_preparedocument @idoc OUTPUT, @RecordXML
insert into #tbl
select ID
FROM OPENXML(@idoc,'/Root/Comp', 1)
WITH (ID varchar(50))
End
By doing this you can get all the data in SQL Temp Table.
Calling of the same Store Procedure.
spSendXML '
Thanks
Dalip Vohra
Custom Text Box with ID and Text in read only mode.
I was having the situation where I have to show the account name in the application and consider accountid in functioning like insert, update.
Point to note here is i don't want to se any kind of list control like dropdown,listbox,etc.
So, I have created my own Text Box control which will provide me the facility to maintain the ID of the text.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public class MyTextBox : TextBox
{
private string _valueID;
public string ValueID
{
get
{
return _valueID;
}
set
{
_valueID = value;
}
}
protected override void OnCreateControl()
{
this.ReadOnly = true;
base.OnCreateControl();
}
}
}
Thanks
Dalip Vohra
Point to note here is i don't want to se any kind of list control like dropdown,listbox,etc.
So, I have created my own Text Box control which will provide me the facility to maintain the ID of the text.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public class MyTextBox : TextBox
{
private string _valueID;
public string ValueID
{
get
{
return _valueID;
}
set
{
_valueID = value;
}
}
protected override void OnCreateControl()
{
this.ReadOnly = true;
base.OnCreateControl();
}
}
}
Thanks
Dalip Vohra
Subscribe to:
Posts (Atom)