{"id":2219,"date":"2012-10-05T12:23:34","date_gmt":"2012-10-05T16:23:34","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=2219"},"modified":"2012-10-05T12:23:34","modified_gmt":"2012-10-05T16:23:34","slug":"multiple-file-upload-vb-net","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2012\/10\/multiple-file-upload-vb-net\/","title":{"rendered":"Multiple file upload &#8211; VB.NET"},"content":{"rendered":"<pre>\r\nCode behind only\r\n<code>\r\nImports System.IO\r\nImports System.Web.UI\r\nImports System.Data.Sql\r\nImports System.Data.SqlClient\r\n\r\n'define public classes\/share them on page\r\nPublic ImgUpConf1 As String                   'displays img after success. upload\r\nPublic ImgUpConf2 As String                   ' \"\r\nPublic BadImgFormat As String                 'passing banned file ext msg to page\r\nPublic NoImage As String = \"no_image.jpg\"     'default image no image jpg\r\nPublic NoImage2 As String = \"no_image_2.jpg\"  'no image jpg for img2, 3 and 4\r\n\r\n'img directory - physical path\r\nDim saveDir As String = \"\\photos\\\"\r\nDim appPath As String = Request.PhysicalApplicationPath\r\n\r\nIf uID = \"\" And vaID = \"\" Then\r\n<a style=\"display:none;\" id=\"te651065575\" href=\"javascript:expand('#te651065575')\">Click to read more...<\/a>\n<div class=\"te_div\" id=\"te651065575\"><script language=\"JavaScript\" type=\"text\/javascript\">expander_hide('#te651065575');<\/script>\r\nMsgLbl.Text = \"Your session expired. Please login again.\"\r\n        \r\nElse\r\n'img extensiong check\r\nDim ImgExt1 As String = System.IO.Path.GetExtension(ImgUpload1.FileName)\r\nDim ImgName1 = \"photo1\" & ImgExt1\r\nDim ImgExt2 As String = System.IO.Path.GetExtension(ImgUpload2.FileName)\r\nDim ImgName2 = \"photo2 & ImgExt2\r\n\r\n'uploading first image\r\nIf (ImgUpload1.HasFile) Then\r\n\r\n'default file name\r\n'Dim savePath As String = \r\n               appPath + saveDir + Server.HtmlEncode(ImgUpload1.FileName)        \r\n\r\n'custom file name               \r\nDim savePath As String = \r\n               Path.Combine(Server.MapPath(\"~\/photos\"), ImgName1)       \r\n\r\n'checking img type = only jpg and gif allowed\r\nIf (ImgExt1.ToString = \".jpg\") Or (ImgExt1.ToString = \".jpeg\") + \r\n                               Or (ImgExt1.ToString = \".gif\") Then\r\n                    \r\nImgUpload1.SaveAs(savePath)\r\nImgUpConf1 = ImgName1.ToString\r\n\r\n'img photo and conf msg after sucess. upload\r\nFileUpd1.InnerHtml = \"&lt;table>\" +\r\n&lt;tr>&lt;td>&lt;img src='..\/photos\/\" & ImgUpConf1 & \"' height='35' width='50'\/>\" +\r\n\"&lt;td style='vertical-align: top;'>&lt;strong>Image 1:\" +\r\n\"&nbsp;\" & ImgUpload1.FileName & \"&lt;br \/>\" +\r\n\"&lt;span class='lblAdded'>Image 1 successfuly uploaded!\"\r\n                \r\nElse\r\n\r\n'if img <> jpg or <> gif msg                  \r\nBadImgFormat = ImgExt1.ToString\r\nImgName1 = NoImage      'db photo record\r\nFileUpd1.InnerHtml = \"&lt;table>\" +\r\n\"&lt;tr>&lt;td>&lt;img src='..\/photos\/no_image.jpg' height='35' width='50'\/>\" +\r\n\"&lt;td style='vertical-align: top;' >&lt;span style='color: red;'>\" +\r\n\"ERROR: The default image format is \" & BadImgFormat & \"!<br \/>\" +\r\n\"Only .jpg and .gif file type allowed.&lt;br \/>\" +\r\n\"&lt;a href='photo_up2.aspx?img=1' class='colorbox2'>Try again.\" +\r\n\"\"\r\n                \r\nEnd If\r\n\r\n'if img is not selected or not required          \r\nElse\r\n                \r\nImgName1 = NoImage      'db photo record\r\nFileUpd1.InnerHtml = \"&lt;table>\" +\r\n\"&lt;tr>&lt;td>&lt;img src='..\/photos\/no_image.jpg' height='35' width='50'\/>\" +\r\n\"&lt;td style='vertical-align: top;' >The default image was not \"+\r\n\"selected and uploaded.&lt;br \/>\" +\r\n\"Default image photo will apply!\"\r\n\r\nEnd If\r\n\r\n'uploading second image\r\nIf (ImgUpload2.HasFile) Then\r\n\r\n'default file name\r\n'Dim savePath As String = \r\n               appPath + saveDir + Server.HtmlEncode(ImgUpload2.FileName)        \r\n\r\n'custom file name               \r\nDim savePath As String = \r\n               Path.Combine(Server.MapPath(\"~\/photos\"), ImgName2)       \r\n\r\n'checking img type = only jpg and gif allowed\r\nIf (ImgExt2.ToString = \".jpg\") Or (ImgExt2.ToString = \".jpeg\") + \r\n                               Or (ImgExt2.ToString = \".gif\") Then\r\n                    \r\nImgUpload2.SaveAs(savePath)\r\nImgUpConf2 = ImgName2.ToString\r\n\r\n'img photo and conf msg after sucess. upload\r\nFileUpd2.InnerHtml = \"&lt;table>\" +\r\n&lt;tr>&lt;td>&lt;img src='..\/photos\/\" & ImgUpConf1 & \"' height='35' width='50'\/>\" +\r\n\"&lt;td style='vertical-align: top;'>&lt;strong>Image 2:\" +\r\n\"&nbsp;\" & ImgUpload2.FileName & \"&lt;br \/>\" +\r\n\"&lt;span class='lblAdded'>Image 2 successfuly uploaded!\" +\r\n\"\"\r\n                \r\nElse\r\n\r\n'if img <> jpg or <> gif msg                  \r\nBadImgFormat = ImgExt1.ToString\r\nImgName2 = NoImage      'db photo record\r\nFileUpd2.InnerHtml = \"&lt;table>\" +\r\n\"&lt;tr>&lt;td>&lt;img src='..\/photos\/no_image.jpg' height='35' width='50'\/>\" +\r\n\"&lt;td style='vertical-align: top;' >&lt;span style='color: red;'>\" +\r\n\"ERROR: The default image format is \" & BadImgFormat & \"!<br \/>\" +\r\n\"Only .jpg and .gif file type allowed.&lt;br \/>\" +\r\n\"&lt;a href='photo_up2.aspx?img=2' class='colorbox2'>Try again.\" +\r\n\"\"\r\n                \r\nEnd If\r\n\r\n'if img is not selected or not required          \r\nElse\r\n                \r\nImgName2 = NoImage      'db photo record\r\nFileUpd2.InnerHtml = \"&lt;table>\" +\r\n\"&lt;tr>&lt;td>&lt;img src='..\/photos\/no_image.jpg' height='35' width='50'\/>\" +\r\n\"&lt;td style='vertical-align: top;' >The default image was not \" +\r\n\"selected and uploaded.\"&lt;br \/>\" +\r\n\"Default image photo will apply!\"\r\n\r\nEnd If\r\n<\/div>\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Code behind only Imports System.IO Imports System.Web.UI Imports System.Data.Sql Imports System.Data.SqlClient &#8216;define public classes\/share them on page Public ImgUpConf1 As String &#8216;displays img after success. upload Public ImgUpConf2 As String &#8216; &#8221; Public BadImgFormat As String &#8216;passing banned file ext msg to page Public NoImage As String = &#8220;no_image.jpg&#8221; &#8216;default image no image jpg Public [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,17,16,52,84],"tags":[19,78,79],"class_list":["post-2219","post","type-post","status-publish","format-standard","hentry","category-net-4-0","category-applications","category-net","category-controls","category-vs2010","tag-asp-net","tag-file","tag-upload"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2219"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=2219"}],"version-history":[{"count":17,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2219\/revisions"}],"predecessor-version":[{"id":2236,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2219\/revisions\/2236"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=2219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=2219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=2219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}