Click here to Skip to main content
13,139,773 members (48,320 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
The code shown below is the part of my application....for the upload images on website also store it in access database and shown it on webpage..Now my problem is....This code works fine on my local PC but couldn't work when I upload it on domain...I used FileUpload control for find out image file and one button...named Button1 used for store and upload the file....

Imports System.Data.OleDb
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim c As New connection()
    Dim r As New Random()
    Dim sb As System.Text.StringBuilder
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            c.cmd = New OleDbCommand("select * from photos where username = 'nikul' ", c.cn)
            Call photos()
        Catch generatedExceptionName As NullReferenceException
            Response.Redirect("~/index.aspx")
 
        End Try
    End Sub
 
    Public Sub photos()
        If c.cn.State = Data.ConnectionState.Open Then c.cn.Close()
        c.cn.Open()
        c.dr = c.cmd.ExecuteReader()
        Dim table As New Table()
        Dim tr As New TableRow()
        Panel1.Controls.Add(table)
        Dim count As Integer = 0
        While c.dr.Read()
            If count = 2 Then
                tr = New TableRow()
                count = 0
            End If
            Dim tc As New TableCell()
            Dim image As New Image()
            image.ImageUrl = "~/photos/nikul/" & c.dr.GetValue(1).ToString()
            image.DescriptionUrl = "~/photos/nikul/" & c.dr.GetValue(1).ToString()
            image.Height = 200
            image.Width = 200
            tc.Controls.Add(image)
            tr.Controls.Add(tc)
            table.Controls.Add(tr)
            count += 1
        End While
        c.dr.Close()
    End Sub
  
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If c.cn.State = Data.ConnectionState.Open Then c.cn.Close()
        c.cn.Open()
        If FileUpload1.HasFile Then
            Dim fi As New System.IO.FileInfo(FileUpload1.FileName.ToString())
            If fi.Extension.ToString() = ".jpg" Or fi.Extension.ToString() = ".png" Or fi.Extension.ToString() = ".bmp" Or fi.Extension.ToString() = ".gif" Or fi.Extension.ToString() = ".jpeg" Or fi.Extension.ToString() = ".JPEG" Or fi.Extension.ToString() = ".JPG" Or fi.Extension.ToString() = ".PNG" Or fi.Extension.ToString() = ".BMP" OrElse fi.Extension.ToString() = ".GIF" Then
                If System.IO.Directory.Exists(Server.MapPath("~/photos/nikul")) Then
                    Dim filename As String = r.[Next](9999).ToString()
                    FileUpload1.SaveAs(Server.MapPath("~/photos/nikul/" & filename))
                    c.cmd = New OleDbCommand("insert into photos values('nikul','" & filename & "')", c.cn)
                    c.cmd.ExecuteNonQuery()
                    Response.Redirect("~/index.aspx")
                Else
                    Dim filename As String = r.[Next](9999).ToString()
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/photos/nikul"))
                    FileUpload1.SaveAs(Server.MapPath("~/photos/nikul/" & filename))
                    c.cmd = New OleDbCommand("insert into photos values('nikul','" & filename & "')", c.cn)
                    c.cmd.ExecuteNonQuery()
                    Response.Redirect("~/index.aspx")
                End If
            Else
                MsgBox("Upload Image file only......", MsgBoxStyle.Information, "Alert")
            End If
        Else
            MsgBox("Please select the file....", MsgBoxStyle.Information, "Alert")
        End If
 
    End Sub
End Class



I didn't get any error on my domain....but i couldn't see the image on my web page...is there any problem with my code???

Go through this link.....http://www.nayanarun.somee.com/[^] for this project preview....
Posted 17-Nov-11 0:30am
Updated 17-Nov-11 22:24pm
v2
Comments
Pandya Anil 17-Nov-11 7:01am
   
Do you have permission to create a file on the server folder (~/photos/nikul) ?
put the code inside a try and catch block and write the exception error on page, it will give you the exact error...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Had you checked permissions for the folder on domain. Permission need to check is read and write for the user. If not Please give permission and check it once
  Permalink  
Comments
NikulDarji 18-Nov-11 2:05am
   
Hey i have done as per your instruction given full control to the folder....and as Anil said first domain prevent me to create "nikul" dir. then I created it manualy...still i wasn't get result...then I tried with only one dir. "photos"....also checked permissions....put my code in try...catch block...no exception was thrown...and still I m not able to seen the image...if want i put the screen shot of webpage....thankx
coded007 18-Nov-11 3:16am
   
can you please put a screen shot
NikulDarji 18-Nov-11 4:25am
   
Go through the link in the question.....
NikulDarji 18-Nov-11 4:30am
   
Hey thankx for your help.....thank you very much.....and I have solved the problem myself..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Don't convert the image in file format....Remove this line..

Dim filename As String = r.[Next](9999).ToString()


and replace the filename with FileUpload1.FileName.ToString()
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 18 Nov 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100