Monday, February 2, 2009

ASP.NET CODE


  1. To Load swf file in asp.net?

ANS.

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub...ersion=8,0,0,0" width="770" height="770" align="middle">

<param name="quality" value="high" />

<param name="bgcolor" value="black" />

<embed src="test.swf" width="770" height="770" loop="false" align="middle" quality="high" bgcolor="black" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />

object>


  1. if you want to transfer sql server database to ms access?

ANS:

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click
 
connetionString = ("server=192.9.200.82;database=eKalyan;_

user id=invite;password=invite")
 
MessageBox.Show("connection established")
sql = ("select newuniqueid,newteh_code,newpcate_cd,newplano, _

pen_nm,rel_cd,pen_fnm,ccate_cd,pan_code,pvillage,ppo_cd,spo_cd,_
start_qtr,last_qtr,bundle_typ,bundle_no,mo_srno,pen_amt,pen_comm,status,_
operatorcode from ekalyan.welpen")
 
cnn = New SqlConnection(connetionString)
Try
cnn.Open()
cmdd = New SqlCommand(sql, cnn)
cmdd.ExecuteNonQuery()
 
cnn.Close()
MsgBox(" ExecuteNonQuery in SqlCommand executed !!")
 
Catch ex As Exception
MsgBox("cannot open the connection")
End Try


End Sub
 
Private Sub Button2_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_

Data Source=C:\database1.mdb")
cn.Open()
 
 
str = "insert into Table1(newuniqueid,newteh_code,newpcate_cd,newplano, _

_nm,rel_cd,pen_fnm,ccate_cd,pan_code,pvillage,ppo_cd,spo_cd,_
start_qtr,last_qtr,bundle_typ,bundle_no,mo_srno,pen_amt,pen_comm,_
status,operatorcode) _
values (@newuniqueid,@newteh_code,@newpcate_cd,@newplano, _
@pen_nm,@rel_cd,@pen_fnm,@ccate_cd,@pan_code,_
@pvillage,@ppo_cd,@spo_cd,@start_qtr,@last_qtr,@bundle_typ,_
@bundle_no,@mo_srno,@pen_amt,@pen_comm,@status,@operatorcode)_
IN 'C:\Table1.mdb'"
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery
cn = Nothing
MessageBox.Show(icount)
 
Catch
End Try
cn.Close()
End Sub
End Class
 
 
3.Send HTML Mail with an Embedded GIF Image and a File Attachment
 
Public Class Form1
Inherits System.Windows.Forms.Form
 
#Region " Windows Form Designer generated code "
 
Public Sub New()
MyBase.New()
 
'This call is required by the Windows Form Designer.
InitializeComponent()
 
'Add any initialization after the InitializeComponent() call
 
End Sub
 
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
 
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
 
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
 Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 24)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(448, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
 
End Sub
 
#End Region
 
' Be sure to use Chilkat .NET v3.2.5 (dated 28-May-2003 or later)
' Download: http://www.emailcomponent.com/ChilkatDotNet.msi
' because a minor problem in displaying HTML emails with attachments
' in certain email clients (not Outlook) has been fixed.
'
' VB.NET program to create an HTML mail and send it.
' Both HTML and plain-text alternative mail bodies are added.
' A GIF image file attachment is also added.
' This example also shows the difference between an attachment
' and a "related item".  The attachment shows as an attached
' file in your mail client (such as Outlook) whereas related
' items are images embedded within the HTML of your email.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
Dim Mailman As New Chilkat.MailMan()
Mailman.UnlockComponent("unlockCode")
 
Dim Message As New Chilkat.Email()
Message.FromAddress = "somebody@chilkatsoft.com"
Message.AddTo("Chilkat Support", "support@chilkatsoft.com")
 
' This is an attachment.
Message.AddFileAttachment("ckActiveX.gif")
 
Dim HTML As String
 
HTML = ""
HTML &= ""
'
'Reset of body here
'
HTML &= "

Test"
HTML &= ""
 
' This adds the GIF image as a related item, to be
' embedded within the HTML of the email.
Dim imageCid As String
imageCid = Message.AddRelatedFile("CkDotNet.gif")
HTML = HTML.Replace("IMG_CID", imageCid)
 
Dim Text As String
Text = "Dear Reader,"
'
'Rest of text alternative message here
'
 
' Set the HTML and plain-text alternative bodies.
Message.SetHtmlBody(HTML)
Message.AddPlainTextAlternativeBody(Text)
Message.Subject = "A subject line"
 
Mailman.SmtpHost = "mail.earthlink.net"
Mailman.SmtpPort = 25
 
' Send the HTML email.
Mailman.SendEmail(Message)
 
End Sub
End Class
 

4. Changing Themes Dynamically in ASP.Net using VB

Imports System.Web.UI.Page
Public Class RDBasePage
Inherits System.Web.UI.Page
Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
'check for new theme
Dim selectedTheme As String = HttpContext.Current.Request("ctl00$ddlTheme")
Dim objCookie As HttpCookie
Try

If selectedTheme > "-" Then 'save new selection
objCookie = New HttpCookie("RDTheme", selectedTheme)
HttpContext.Current.Response.Cookies.Add(objCookie)
Else 'get theme from cookie

objCookie = HttpContext.Current.Request.Cookies("RDTheme")
If Not objCookie Is Nothing Then selectedTheme = objCookie.Value
End If
Catch
ex As Exception
Finally
objCookie = Nothing
End Try
If selectedTheme <= "-" Then selectedTheme = "gray"
Page.Theme = selectedTheme
End Sub
End Class


The code needed on my web pages is very simple:

Partial Class _Default
Inherits RDBasePage

End Class

5.open pdf file in asp.net

ANS:
public void ProcessRequest(HttpContext context)
2 {
3   //context.Response.Write("Hello World");
4   String sFileName = "";
5   String sFullPath = String.Empty;
6   sFullPath = context.Request.QueryString["FullPath"];
7   if (sFullPath != null && sFullPath.Length > 4)
8   {
9      if (sFullPath.Contains(@"\"))
10     {
11       if (File.Exists(sFullPath))
12        {
13         FileInfo _file4View = new FileInfo(sFullPath);
14         context.Response.Buffer = false;
15         context.Response.Clear();
16         String sContentType = "";
17         switch (Path.GetExtension(sFullPath).ToLower())
18         {
19          case ".dwf":
20          sContentType = "Application/x-dwf";
21          break;
22          case ".pdf":
23          sContentType = "Application/pdf";
24          break;
25          case ".doc":
26          sContentType = "Application/vnd.ms-word";
27          break;
28          case ".ppt":
29          case ".pps":
30          sContentType = "Application/vnd.ms-powerpoint";
31          break;
32          case ".xls":
33          sContentType = "Application/vnd.ms-excel";
34          break;
35          default:
36          sContentType = "Application/octet-stream";
37          break;
38         }
39         Context.Response.ContentType = sContentType;
40         MemoryStream _Stream = new MemoryStream();
41         //StreamWriter _writer = new StreamWriter(_Stream);
42         FileStream _fileStream = new FileStream(sFullPath, FileMode.Open,_

FileAccess.Read);
43         long fileLength = _fileStream.Length;
44         Byte[] _byte = new Byte[(int)fileLength];
45        _fileStream.Read(_byte, 0, (int)fileLength);
46        _fileStream.Close();
47        context.Response.BinaryWrite(_byte);
48     }
49   }
50  }
51 }



[How to] Removing the ntdetec1.exe virus
Author: Samir Mistry


Today is the world of flash drives.
Everyone you know now has a PD ( Pen drive ) and wants you
to copy some files off your PC / Mac.

Now, unlike me, if you’re using the
oh-so-prone-to-viruses Operating System called Windows,
chances are that you might have already come across
the ntdetec1.exe virus. Or you will, sooner or later.

Its official name is W32.Ceted and it is a worm that
copies itself to all shared and removable drives and
spreads when the user double clicks on it to open it.
If a system is infected, it creates a folder called ntdetec1
in your System Drive which is NOT visible via Explorer or Command prompt.

Related files:
\ntdetec1\ntdetec1.exe
\ntdetec1\cmrss.exe
\ntdetec1\run.exe
\ntdetec1\shell32.exe
\ntdetec1\drivelist.txt
\ntdetec1\child\autorun.inf
\ntdetec1\child\ntdetec1.exe

Symptoms:
1. Task Manager closes as soon as it launches.
2. RegEdit may be inaccesible
3. Folder Options may be inaccessible

When I scanned using some anti-virus software, Nod32,
Symantec AV Corporate, McAfee and AVG failed to detect
the files, even in Safe Mode.

To remove it, run the following commands at the command prompt:

taskkill /im cmrss.exe
taskkill /im ntdetec1.exe
taskkill /im shell32.exe

Now, make sure you are in the root drive of your system.
For example, if your Windows in installed in C:,
make sure your prompt shows C:\>
Now, run the command..

attrib ntdetec1 -s -h /s /d

This will make the folder visible in explorer.
Now you can Shift+Delete the folder from explorer.

Also, you might need to delete the following registry key (if it is present)

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
\CurrentVersion\policies\Explorer\ Run\"winlogon" = "C:\ntdetec1\run.exe"

Congratulations, this will remove all known traces of the above worm.

And remember, next time you use someone’s PD,
before you access it, goto your command prompt and
delete the autorun.inf file if any.