Wednesday, September 22, 2010

VB 6.0 Create Backup of a Table

mdbpassword = "9990513523"
file2 = "account.mdb"
cn3.Open "Provider=MSDataShape.1;Data Provider = Microsoft.Jet.OLEDB.3.51;Jet OLEDB:Database Password=" & mdbpassword & ";data source=" & file2
c = InputBox("Enter Table Name to Save::::Use only Numbers and Alphabets..", "Save Table")
If c = "" Then
cn3.Close
Exit Sub
Else
cn3.Execute "select * into [" & c & "] from attendance"
cn3.Execute "delete values from attendance"
cn3.Close
MsgBox "Table " & c & " Saved", vbInformation, "Saving Information..."
Att.Refresh
End If

VB 6.0 Show All Table Names in ComboBox

Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
mdbpassword = "9990513523"
file2 = "account.mdb"

con.Open "Provider=MSDataShape.1;Data Provider = Microsoft.Jet.OLEDB.3.51;Jet OLEDB:Database Password=" & mdbpassword & ";data source=" & file2

Set rs = con.OpenSchema(adSchemaTables)

While Not rs.EOF
If rs("TABLE_TYPE") = ("TABLE") Then
Combo1.AddItem rs!TABLE_NAME

End If
rs.MoveNext
Wend

Tuesday, September 21, 2010

VB.NET Rename a File

//imports System.IO

Dim ddl As String
ddl = DropDownList1.Text
My.Computer.FileSystem.RenameFile("d:\kapil\uploaded\updatemaster.mdb", ddl & ".mdb")

Monday, September 20, 2010

VB.NET Download/Upload From FTP

//download

Private Sub ftpp()
Dim localFile As String = "C:\Inetpub\wwwroot\order\images\updatemaster.mdb"
Dim remoteFile As String = "/kapil/updatemaster.mdb"
Dim host As String = "ftp://ftp.sdmftp.com"
Dim URI As String = host & remoteFile
Dim username As String
Dim password As String
username = "rpc"
password = "rpc123"
Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)
ftp.Credentials = New System.Net.NetworkCredential(username, password)
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
Using response As System.Net.FtpWebResponse = _
CType(ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream
'loop to read & write to file
Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0 'see Note(1)
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using
MsgBox("downloaded")
End Sub

//Upload
Private Sub ftppu()
Dim localFile As String = "C:\Inetpub\wwwroot\order\images\updatemaster.mdb"
Dim remoteFile As String = "/kapil/updatemaster.mdb"
Dim host As String = "ftp://ftp.sdmftp.com"
Dim URI As String = host & remoteFile
Dim username As String
Dim password As String
username = "rpc"
password = "rpc123"

Dim reqObj As FtpWebRequest = WebRequest.Create(URI)
reqObj.Method = WebRequestMethods.Ftp.UploadFile
reqObj.Credentials = New NetworkCredential(username, password)
Dim streamObj As FileStream = File.OpenRead(localFile)
Dim buffer(streamObj.Length) As Byte
streamObj.Read(buffer, 0, buffer.Length)
streamObj.Close()
streamObj = Nothing
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length)
reqObj = Nothing
End Sub

Saturday, September 18, 2010

Password Protected Internet Explorer

Start Internet Explorer, then go to the 'Tools' heading on the toolbar. Click on 'Internet Options.'

Select the 'Content' tab.

Click on the 'Enable' button.

Make your access selections, then click on 'OK.'

Choose a password when Internet Explorer asks you to do so. Type the password into the provided field.


Wednesday, September 15, 2010

VB.NET Add Title to Your aspx Page


//Go To Source view from Design View and at the Top of the Page Just add this red underlined line

VB.NET Place ICON of your website into Browser AddressBar


//Go to Source Page from Design View and write this line after "head tag"
// Where folder path is C:/inetpub/wwwroot/Yourwebsitefolder/images/n.ico


VB.NET Marquee

Thursday, September 9, 2010

VB.NET Web.Config File with ConnectionString


//For Access
//Imports System.Data.Oledb

Dim cmd As New OleDbCommand
Dim cnmdb As OleDbConnection = New OleDbConnection(ConfigurationSettings.AppSettings("ConnectionStringmdb"))
cnmdb.Open()
cmd = New OleDbCommand("insert into mainmaster values('" & txtname.Text & " ','" & txtcontact.Text & "','" & txtbilladd.Text & "',)", cnmdb)

cmd.ExecuteNonQuery()

//For Sqlserver
//Imports System.Data.Sqlclient

Dim cmd As New SqlCommand
Dim cn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
cn.Open()
cmd = New SqlCommand("insert into mainmaster values('" & txtname.Text & " ','" & txtcontact.Text & "','" & txtbilladd.Text & "',)", cn)

cmd.ExecuteNonQuery()


VB.NET GridView Extract Selected Row Value


//on Download Button Click (Download Selected checkbox row index file)

Dim CheckBox As CheckBox

For Each row As GridViewRow In GridView1.Rows
CheckBox = CType(row.FindControl("checkbox1"), CheckBox)
If CheckBox.Checked Then
Response.AppendHeader("Content-Disposition", "attachment; filename=" + row.Cells(1).Text)

Response.TransmitFile("f:/soft/KapiL/uploaded/" + row.Cells(1).Text)
//Response.TransmitFile(Server.MapPath("~/uploaded/" + row.Cells(1).Text))

Response.End()
End If
Next

Monday, September 6, 2010

VB.NET Send Mail



imports System.Net.Mail
Dim mail As New MailMessage()
mail.From = New MailAddress("" & txtfrm.Text & "")
mail.To.Add("" & txtto.Text & "")

mail.Subject = "" & txtsub.Text & ""
mail.Body = "" & txtmsg.Text & ""
mail.IsBodyHtml = True

Dim file As String = "" & txtatch.Text & ""
If Not file = "" Then
Dim MsgAttach As New Attachment(file)
mail.Attachments.Add(MsgAttach)
End If

Dim smtp As New SmtpClient("mail.suprol.com")
smtp.Send(mail)
lblmail.Text="mail sent successfully..!!"
//With a copy send to mailsender with date time
Dim mail As New MailMessage()
Dim mailrep As New MailMessage()

mail.From = New MailAddress("" & txtfrm.Text & "")
mail.To.Add("" & txtto.Text & "")

mailrep.From = New MailAddress("" & txtfrm.Text & "")
mailrep.To.Add("" & txtfrm.Text & "")
mailrep.Subject = "Mail sent To" & "" & " " & txtto.Text & ""
mailrep.Body = "Your Mail successfully Sent To" & " " & "" & txtto.Text & "" & " " & "Date and Time was : " & " " & "" & DateTime.Now() & "" & " " & "With Attachment File Name :" & " " & "" & txtatch.Text & ""
mailrep.IsBodyHtml = True


mail.Subject = "" & txtsub.Text & ""
mail.Body = "" & txtmsg.Text & ""
mail.IsBodyHtml = True
Dim filerep As String = "" & txtatch.Text & ""
Dim file As String = "" & txtatch.Text & ""
If Not file = "" Then
Dim MsgAttach As New Attachment(file)
mail.Attachments.Add(MsgAttach)
mailrep.Attachments.Add(MsgAttach)
End If

Dim smtp As New SmtpClient("mail.suprol.com")
smtp.UseDefaultCredentials = False
smtp.Port = 2525
smtp.Send(mail)
smtp.Send(mailrep)

VB.NET Upload & Download a file

// UPLOAD
//drag fileupload control for path and a button for upload

Dim file As String
file = Path.GetFileName(FileUpload1.FileName)
FileUpload1.SaveAs("C:\Inetpub\wwwroot\order\images\" + file)
//it is better to save file in another folde rather than the inetpub JUST LIKE BELOW
FileUpload1.SaveAs("d:\kapil\images\" + file)
lblupload.Text = "File Upload Complete...."
labelsize.text=FileUpload1.PostedFile.ContentLength

//DOWNLOAD

Response.AppendHeader("Content-Disposition", "attachment; filename=ecc1.jpg")
Response.TransmitFile(Server.MapPath("~/images/ecc1.jpg"))
//Response.TransmitFile("d:/kapil/images/ecc1.jpg")
Response.End()

//By Default, maximum allowed size for file is 4MB. To allow files larger than the default of 4MB, one need to change the web.config file(in system.web TAB).There is a parameter called maxRequestLength which takes value in the KB.
 


//1048576 is around 1GB