VB.NET - asp.net

Asked By kshama parashar
01-Sep-10 06:54 AM
how to save image in a directory in vb.net window application
  Reena Jain replied to kshama parashar
01-Sep-10 07:48 AM
hi

here is the code for you

Private Sub browse_butt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles browse_butt.Click

      'TextBox1 as string = ""

      'Image.Title = "Set Image File"

      Image.Filter = "Jpeg files (*.jpeg)|*.jpg|All files (*.*)|*.*"

      Image.DefaultExt = "jpeg"

      Image.FilterIndex = 1

      Image.FileName = ""

      Image.ShowDialog()




      sFilePath = Image.FileName

      TextBox1.Text = sFilePath


      'string DefaultExt = Path.GetExtension(FileName);
      imageFile = TextBox1.Text
    


    End Sub

    Private Sub clear_butt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear_butt.Click
      TextBox1.Text = ""
    End Sub

    Private Sub sub_butt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sub_butt.Click
      ''Dim fs As FileStream = New FileStream(TextBox1.ToString(), FileMode.Open)

      ''Dim img As Byte() = New Byte(fs.Length) {}

      ''fs.Read(img, 0, fs.Length)

      ''fs.Close()

      ''imageFile = Image.FromFile(TextBox1.ToString())

      'Dim strConnect As String

      'strConnect = "Data Source=bxswlt;Initial Catalog=ImageGallery;User ID=sa"

      'Dim conn As MySqlConnection = New MySqlConnection(strConnect)



      'Dim sSQL As String = "UPDATE coordinate SET lakaran_kejadian VALUES (@TextBox1)"

      ''UPDATE `accidentdata2006`.`accident_info` SET `lakaran_kejadian` =

      'Dim cmd As SqlCommand = New SqlCommand(sSQL, conn)


      Dim sSavePath As String
      sSavePath = "images/"

      Dim pic As Image
      'imageFile = Image.f


      Dim fileName As String = Image.FileName.ToString()
      'Dim userName As String = Profile.UserName
      Dim uploadFolderPath As String = "~/upload/"
      Dim filePath As String = HttpContext.Current.Server.MapPath(uploadFolderPath)
      'Directory.CreateDirectory(filePath + "\" + userName)
  Super Man replied to kshama parashar
01-Sep-10 08:23 AM

This works in windows application.

Above code by @reena work for website

 

 

      'here assumed that you have image named as i

      Dim i As Image

 

      ' here set direcory as you want

      Dim Dir_path As String = "c:\hello\"

 

      'set imagename as you want

      Dim image_name As String = "hello.jpg"

 

      ' saves image

      i.Save(Dir_path + image_name)

Create New Account
help
class _Default : System.Web.UI.Page { SqlConnection conn = new SqlConnection(); protected void Page_Load( object sender, EventArgs e) { conn.ConnectionString = " Data Source = MyServer; Integrated Security = True; database = test" ; Load_GridData(); / / call method below how to display images in GridView from DataBase in ASP.NET using C#.NET and VB.NET or showing images stored in SQL Server database in gridview, For this i've already visit link below Upload / Save Images in Database using FileUpload Control in ASP.NET C# VB.NET For displaying images in gridview we need to create a Handler to read binary data HttpContext context) { SqlConnection con = new SqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings ["ConnectionString"].ConnectionString; / / Create SQL Command SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Select ImageName, Image from Images" + " where ID = @ID"; cmd.CommandType = System.Data.CommandType dReader = cmd.ExecuteReader(); dReader.Read(); context.Response.BinaryWrite((byte[])dReader["Image"]); dReader.Close(); con.Close(); } VB.NET Code Public Class Handler Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Dim
to Byte Array string filePath = Server.MapPath( "APP_DATA / TestDoc.docx" ); string filename = Path .GetFileName(filePath); FileStream fs = new FileStream (filePath, FileMode .Open, FileAccess .Read); BinaryReader br = new BinaryReader (fs); Byte [] bytes = br.ReadBytes(( Int32 )fs.Length); br.Close(); fs.Close(); VB.Net ' Read the file and convert it to Byte Array Dim filePath As String = Server.MapPath APP_DATA / Testxls.xlsx" ) Dim filename As String = Path.GetFileName(filePath) Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read) Dim br As BinaryReader = New BinaryReader(fs) Dim bytes As Byte () = br
using a stored proc which would just update a blob column in your table using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { byte [] imageData = new Byte[fs.Length]; fs.Read( imageData, 0, ( int )fs.Length ); } using ( SqlConnection conn = new SqlConnection(connectionString) ) { SqlCommand cmd = new SqlCommand( "DoTheStorageSP" , conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add( "@filename" , filename ); cmd.Parameters[ "@filename" ].Direction system hard disk and show the image in Picturebox control. private void btnUploadImage_Click(object sender, EventArgs e) { try { / / create an object of OpenFileDialog to browse image OpenFileDialog open = new OpenFileDialog(); / / filter so we can store this image into the database table. private void btnSave_Click(object sender, EventArgs e) { try { if (Validate() && convertImage()) { insertImage(); } } catch { } } public bool Validate() { try { if (Convert.ToInt32(txtid we want to perform string query = "insert into imagedata values("+id+", '" + photo + "')"; / / create object of Sqlcommand class and pass two parameters sqlserver query and sqlconnection con SqlCommand cmd = new SqlCommand(query
File upload and store file path vb.net VB.NET Hi I am attemting to use an upload control that saves large files and writes type. But I feel saving the file location would improve db performance. I am using vb.net visual studio 2010 and I am unsure how to implement this. Thanks in advance. Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click If IsPostBack Then Dim path As String = Server.MapPath("~ / UploadedVideos / "+FileUploadVideo.filename VideoName], [CourseNo], [ModuleNo], [MIME], [VideoData]) VALUES (@VideoName, @CourseNo, @ModuleNo, @MIME, @VideoUrl)" Dim cmd As New SqlCommand(SQL, Conn) cmd.Parameters.AddWithValue("@VideoName", txtVideoName.Text.Trim()) cmd.Parameters.AddWithValue("@CourseNo", cboCourse.SelectedValue
Saving and Retrieving pictures using VB.Net Please assist me in saving pictures in access database and retrieve them using visual basic code You can save the Images and retrive the image from the SQL SERVER using VB.NET Check this link Save and Retrive Images Use this code for VB.Net- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim imagedata As Byte() imagedata = File.ReadAllBytes("c: \ a.bmp") Dim cn 8;Initial Catalog = JitendraDB;User ID = sa;password = change_123" cn.Open() Dim cmd As New SqlCommand("insert into empimage (empid, empimage) values('1211', @ImageData)", cn) cmd.Parameters.AddWithValue("@ImageData", imagedata) cmd