Iron Speed Technical Forums
Register Latest Topics
 
 
 


Reply
  Author   Comment  
Bang

Registered:
Posts: 14
Reply with quote  #1 
I have made the code customization, 
Upload a File to the File System
http://www.ironspeed.com/Designer/12.2.0/Code%20Customizations/ShowCodeCustomization.aspx?codeCustomizationName=/Designer/12.2.0/Code%20Customizations/cs/Attachments/Upload%20a%20File%20to%20the%20File%20System&displayType=code&scriptLanguage=vb#gsc.tab=0ut

I want to have the file can be uploaded to the system and not uploaded to the database.

there is an error as follows: 
Capture.jpgHow to solve it?

This is the code :

Code:

    Dim inputFile As System.Web.UI.HtmlControls.HtmlInputFile
  
    inputFile = CType(Me.Page.FindControl("UploadFile"), System.Web.UI.HtmlControls.HtmlInputFile)
    '' If this code customization was added to Table Control Row, replace FindControlRecursively() with FindControl()
  '' or comment out the above line of code and uncomment the line below
  '' inputFile = CType(Me.FindControl("inputFile"), System.Web.UI.HtmlControls.HtmlInputFile)
     
    If (Not inputFile.PostedFile Is Nothing) And _
       (inputFile.PostedFile.ContentLength > 0) Then
        ' Get the name of the file to be uploaded and 
        ' the location where the file needs to be saved.
        Dim fileName As String = System.IO.Path.GetFileName(inputFile.PostedFile.FileName)
        Dim saveLocation As String = Me.Page.Server.MapPath("C:\inetpub\wwwroot\eDocument\Data") & "\" & fileName
        Try
            'Save the file.
            inputFile.PostedFile.SaveAs(saveLocation)
            me.Page.Response.Write("The file has been uploaded.")
        Catch exc As Exception
            me.Page.Response.Write("Error: " & exc.Message)
        End Try
    Else
        me.Page.Response.Write("Please select a file to upload.")
    End If



Please Help....[bawl][bawl]

Thanks
Regard,

Bang

Rexxrally

Registered:
Posts: 240
Reply with quote  #2 
This line is the problem:

Dim saveLocation As String = Me.Page.Server.MapPath("C:\inetpub\wwwroot\eDocument\Data") & "\" & fileName


You can't reference a location on the server like you do on your local computer.
Your website on the server is a sandbox, so you can't upload to a location outside it.

You have to create a folder in your website, perhaps called UploadedFiles and then do this:


Dim saveLocation As String = Me.Page.Server.MapPath("..\UploadedFiles") &"\" & fileName



This will expect a folder called UploadedFiles in the root folder of your website.


Bang

Registered:
Posts: 14
Reply with quote  #3 
Thanks for your reply,

I have tried it, but the result is the same...
porphi

Registered:
Posts: 648
Reply with quote  #4 
Bang,

  First make sure inputFile is not null.

Phil

__________________
Thank you,
Phil Porter
PPG&A, INC.
pporter@ppgainc.com
http://www.ppgainc.com
https://rapidsprout.com
678-362-2035
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.

Download Iron Speed Designer

Terms of Service Privacy Statement