Posts

Showing posts from March, 2008
SQL Stored Procedure to Send Email using OLE You Just need to change SMTP Server address CREATE PROCEDURE [dbo].[WSA_sp_SendEmail]@From varchar(100),@To varchar(1000),@Subject varchar(250),@Body varchar(max),@CC varchar(1000) = nullASBEGINDeclare @iMsg intDeclare @hr intDeclare @source varchar(255)Declare @description varchar(500)Declare @output varchar(1000)EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUTPrint @FromEXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', '10.0.0.100'EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null--Print @ToEXEC @hr = sp_OASetProperty @iMsg, 'To', @ToEXEC @hr = sp_OASetProperty @iMsg, 'From', @Fromif (@Cc <> '')EXEC @hr = sp_OASetProperty @iMsg, &

To Read and Write to Text file from ASP.NET

To Write C# code If the file does not exist you will get an error. You can check to see if the file exists using this code: if (System.IO.File.Exists(Server.MapPath("test.txt"))) To write the contents of a TextBox control to a text file using the System.IO.StreamWriter class use the following code: System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(Server.MapPath("test.txt")); StreamWriter1.WriteLine(TextBox1.Text); StreamWriter1.Close(); Inserting "\r\n" will create a line break in the text file. Adding line breaks from code can be done using this code: StreamWriter1.WriteLine("Some text on line1.\r\nSome text on line2."); To Read c# code System.IO.StreamReader StreamReader1 = new System.IO.StreamReader(Server.MapPath("test.txt")); TextBox2.Text = StreamReader1.ReadToEnd(); StreamReader1.Close();

To Insert Data into Excel using Office object libray

C# file code using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using Microsoft.Office.Interop.Excel; using System.Reflection; using Microsoft.Office.Core; using System.Drawing; using SAMSBusinessLayer; using SAMSDataAccessLayer; using System.IO; using System.Diagnostics; public partial class Admin_Report_SamsReport : basePageSessionExpire { #region Private_Variable Microsoft.Office.Interop.Excel.Application excelapp; Microsoft.Office.Interop.Excel.Workbook wb; int iSelectedMonth = 0; int iSelectedYear = 0; ExecuteSummaryDataFilter objExecuteSummaryDataFilter; ExecuteSummaryData objExecuteSummaryData; int iRowNo_for_Executive_Summary_Sheet = 1; int iRowNo_for_Slide_Views_Sheet = 1; int iRowNo_for_Fulfillment_Report_Sheet = 1; string Table_Logins_By_Month_StartRange = "&q