First timer ASP.NET uploading.

S

SHiGE

Guest
I know there is a few of this topic. But i couldn't find my answer.

I have the following code that work fine on my localhost.
Code:
Dim FolderPath As String = ConfigurationSettings.AppSettings("PromotionUpload")
Dim MaxSize As Integer = ConfigurationSettings.AppSettings("PromotionImgSize")

'Checking filetypes
If Selected.PostedFile.ContentType = "image/pjpeg" Or Selected.PostedFile.ContentType = "image/jpeg" Then
Else
    Return "The file you selected for upload is invalid! Only JPEG (*.jpg) files are allowed."
End If

'Checking for duplication
If Overwrite = False Then
    Dim Directory As DirectoryInfo = New DirectoryInfo(MapPath(FolderPath))
    Dim ExistingFiles() As FileInfo = Directory.GetFiles("*.jpg")
    For Each myFile As FileInfo In ExistingFiles
         If myFile.Name = Selected.PostedFile.FileName Then
             Return "The file you selected for upload already exist in the server!"
         End If
    Next
End If

'Checking for size
If Selected.PostedFile.ContentLength / 1024 > MaxSize Then
    Return "The file you selected for upload exceeded the allowable " & MaxSize & "KB file size!"
End If

'Uploading
Selected.PostedFile.SaveAs(Server.MapPath(FolderPath) & Selected.Value)

But when i uploaded to jodohost, i couldn't upload it.

Do i need to set any permission on the folder that i'm going to upload to? or is the server disallow me trying to get the exisiting filelist for duplication checking?

Please help.
 
I've been using the code below to upload fairly large pdfs with good results:

Code:
<script language="VB" runat="server">

Private strGalleryPath = "/yourdirectory/"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
  Dim SourceFile As HttpPostedFile, ThumbnailFile As HttpPostedFile
    'Fetch source file and save it to disk
    SourceFile = Request.Files("file")
	'Save the file with the record ID as the name
    Dim strFileName As String = Request.QueryString("yourrecordID") & ".pdf"
    SourceFile.SaveAs (Server.MapPath("/yourdirectory/" & strFileName))
	response.Redirect("docuploadcomp.asp")
End Sub
</script>

Obviously, you'll need to change "yourdirectory" to the directory name on the server and make adjustments for the filename (strFileName) and redirect.
 
Back
Top