Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. using file uploader in a gridview

using file uploader in a gridview

Scheduled Pinned Locked Moved ASP.NET
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chathu03j
    wrote on last edited by
    #1

    I want to have a File uploader inside a grid view control. I have bound this grid view to a datasource, so can I use the file uploader inside the gridview? I will have to writer manual coding to upload the file, isn't it? can somebody tell me how I can sent the filename of the uploaded file to the datasource parameter?? thanks for any answer!!!

    K 1 Reply Last reply
    0
    • C chathu03j

      I want to have a File uploader inside a grid view control. I have bound this grid view to a datasource, so can I use the file uploader inside the gridview? I will have to writer manual coding to upload the file, isn't it? can somebody tell me how I can sent the filename of the uploaded file to the datasource parameter?? thanks for any answer!!!

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      You can put a file uploader in a gridview control, you just need to use a Item Template for the column you want it to be in. Here is some sample code from Microsoft help:

      Visual Basic
      Protected Sub Page_Load(ByVal sender As Object,
      ByVal e As System.EventArgs) Handles Me.Load
      If IsPostBack Then
      Dim path As String = Server.MapPath("~/UploadedImages/")
      Dim fileOK As Boolean = False
      If FileUpload1.HasFile Then
      Dim fileExtension As String
      fileExtension = System.IO.Path. _
      GetExtension(FileUpload1.FileName).ToLower()
      Dim allowedExtensions As String() = _
      {".jpg", ".jpeg", ".png", ".gif"}
      For i As Integer = 0 To allowedExtensions.Length - 1
      If fileExtension = allowedExtensions(i) Then
      fileOK = True
      End If
      Next
      If fileOK Then
      Try
      FileUpload1.PostedFile.SaveAs(path & _
      FileUpload1.FileName)
      Label1.Text = "File uploaded!"
      Catch ex As Exception
      Label1.Text = "File could not be uploaded."
      End Try
      Else
      Label1.Text = "Cannot accept files of this type."
      End If
      End If
      End If
      End Sub

      Hope that helps. Ben C# protected void Page_Load(object sender, EventArgs e) { if(IsPostBack) { Boolean fileOK = false; String path = Server.MapPath("~/UploadedImages/"); if (FileUpload1.HasFile) { String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); String[] allowedExtensions = {".gif", ".png", ".jpeg", ".jpg"}; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } if (fileOK) { try { FileUpload1.PostedFile.SaveAs(path + FileUpload1.FileName); Label1.Text = "File uploaded!"; } catch (Exception ex) { Label1.Text = "File could not be uploaded."; } } else { Label1.Text = "Cannot accept files of th

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups