Monday, July 12, 2010

Using C# and VB.NET classes together in the App_Code folder

Create two folders under App_Code filder named CSCode and VBCode. Move Class1.cs inside CSCode folder and Class2.vb inside VBCode folder.


Error 1 The files ‘/VBandCSharptogether/App_Code/Class2.vb’ and ‘/VBandCSharptogether/App_Code/Class1.cs’ use a
different language, which is not allowed since they need to be compiled together.


if You got error this then add this following code to web.config file


<compilation debug="true">
<codeSubDirectories>
<add directoryName="CSCode"/>
<add directoryName="VBCode"/>
</codeSubDirectories>
</compilation>

Tuesday, July 6, 2010

Compare multiple TextField through javascript

this code not allow the same text in any two text field

function comp_txt(present)
{
dml=document.forms['aspnetForm'];
var i;
var per=document.getElementById(present);
for(i=0;i {
if(per.name == dml.elements[i].name)
{
}
else if(per.value == dml.elements[i].value)
{
per.value="";
}
}
}



you can call on onChange event and pass argument id of current

text field

Only Numeric Value Allow In TextBox in JavaScript


function funi(t) {

//var t=document.getElementById(r);
if (!(t.keyCode >= 48 && t.keyCode <= 57)) {
t.keyCode = 0;
}
}

Call this like following

<input type="text" onkeypress="funi(event)"></input>

Monday, June 28, 2010

Backup Of All Database of SQL which are attached


DECLARE @path VARCHAR (500) /* Path of the Backup Files */

DECLARE @folderdate VARCHAR (75) /* The subdir for my backups with Format YYYYMMDD */

DECLARE @cmd VARCHAR (4000) /* The command to create Subdir */

DECLARE @DBName varchar(255)

DECLARE @DATABASES_Fetch int

DECLARE @PreciceDateTime varchar(255)

DECLARE @ServerName varchar(50)

DECLARE @NetworkBackupShare varchar(75)



--Network or local disk path you wish to use, such as D:\Backup

SET @NetworkBackupShare = N'C:\backup'



--Create a dynamic path for the backup of the databases based on datetime



EXEC sp_configure 'show advanced options', 1;

RECONFIGURE;

EXEC sp_configure 'xp_cmdshell', 1;

RECONFIGURE;

/* gives us YYYYMMDD

hour hh

minute mi, n

second ss, s

*/


--PRINT @folderdate



SET @ServerName = (SELECT @@servername)

/* Path as C:\Backup\YYYYMMDD */

SET @path ='
'

/* Create the command that will do the creation of the folder*/

SET @cmd = N'mkdir ' + @path

--PRINT @cmd

/* Create the new directory */

EXEC master.dbo.xp_cmdshell @cmd , no_output

/* now I can direct all the backup file to the created subdirectory like,

SET filename = path [other_variable/s] ‘.BAK‘ */

/*******************************************/

--Now let's actually do the backups to the path created above

DECLARE DATABASES_CURSOR CURSOR FOR

select

DATABASE_NAME = db_name(s_mf.database_id)

from

sys.master_files s_mf

where

-- ONLINE

-- s_mf.state = 0



-- Only look at databases to which we have access

has_dbaccess(db_name(s_mf.database_id)) = 1



-- Not master, tempdb or model

and db_name(s_mf.database_id) not in ('Master','tempdb','model')

group by s_mf.database_id

order by 1

OPEN DATABASES_CURSOR

FETCH NEXT FROM DATABASES_CURSOR INTO @DBName

WHILE @@FETCH_STATUS = 0

BEGIN

declare @DBFileName varchar(256)

set @DBFileName = --datename(dw, getdate()) + ' - ' +

replace(replace(@DBName,':','_'),'\','_') + '.BAK'

PRINT @path

exec ('BACKUP DATABASE [' + @DBName + '] TO DISK = ''' + @path +

@DBFileName + ''' WITH NOFORMAT, INIT, NAME = N''' +

@DBName + '-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD, STATS = 100')



FETCH NEXT FROM DATABASES_CURSOR INTO @DBName

END

CLOSE DATABASES_CURSOR

DEALLOCATE DATABASES_CURSOR

Thursday, June 24, 2010

Changing the tab index of AJAX Tab control through Javascript


function SetActiveTab(tabControl, tabNumber)
{
var ctrl = $find(tabControl);
ctrl.set_activeTab(ctrl.get_tabs()[tabNumber]);
}

Here
1.tabControl is client id of tabcontainer.
2.tabNumber is tab index as numeric


to pass Client ID use this

<input type="Button" onClick="SetActiveTab('<%=tabControl.ClientID%>',2);"
value="Next"> </input>

Overview of Popular JavaScript Frameworks - ASP.NET AJAX

Overview of Popular JavaScript Frameworks - ASP.NET AJAX

Form Validation using jQuery

Form Validation using jQuery

Wednesday, June 23, 2010

Sending E-mail with uploaded attachment

 protected void Btn_Send_Click(object sender, EventArgs e)
{


try
{

string to =Txt_To.Text;

string[] str = to.Split(';');
string from = Txt_From.Text;
string from_pwd = "12345678";
MailMessage mM = new MailMessage();
mM.From = new MailAddress(from);

foreach (string s in str)
{
mM.To.Add(s);
}

mM.Subject = Txt_Subject.Text;
mM.Body = Txt_message.Text;
mM.IsBodyHtml = true;

string s1 = "";


mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("mail.kumbhaj.com");
sC.UseDefaultCredentials = false;
sC.Port = 25;


if (FileUpload1.HasFile)
{
FileInfo f = new FileInfo(FileUpload1.FileName.ToString());
s1 = Guid.NewGuid().ToString();
s1 = "uploadfile/" + s1 + f.Extension;
FileUpload1.SaveAs(Server.MapPath(s1));
Attachment at = new Attachment(Server.MapPath(s1));
mM.Attachments.Add(at);
}

sC.Credentials = new System.Net.NetworkCredential(from, from_pwd);
sC.EnableSsl = false;
sC.Send(mM);
Lbl_Failled_Report.Text = "Message Successfully send.";
}
catch (Exception ex)
{
Lbl_Failled_Report.Text = "Message sending Failled!";
}
}

Tuesday, June 22, 2010

To Add Column Through Stored Procedure.


you can pass the name 
of column as parameter 

CREATE PROCEDURE AddColumnToTable
@columnName VARCHAR(128)
AS
EXEC ('ALTER TABLE tableName ADD' + SPACE(1) +
 @columnName + SPACE(1) + 'VARCHAR(MAX) NULL')

For Sending Email Through C#



using System;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace TestingConsole
{
class Program
{
static void Main(string[] args)
{
try
{
string to = "to@domain.com";
string from = "from@gmail.com";
string from_pwd = "mypassword";
string subject = "Sample Mail testing";
string body = "Wow this is testing body";
MailMessage mM = new MailMessage();
mM.From = new MailAddress(from);
mM.To.Add(to);
mM.Subject = subject;
mM.Body = body;
mM.IsBodyHtml = false;
mM.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
sC.Port = 587;
sC.Credentials = new NetworkCredential(from,
               from_pwd);
sC.EnableSsl = true;
sC.Send(mM);
}
catch (Exception e)
{
Console.WriteLine(e.Message + " " + e.StackTrace);
}
}
}
}

You can use in window or web application accordig to you need.