Professional Web Applications Themes

File Field - ASP.NET General

I am coding a ASP to process a excel file and output the reults to a text file. To browse for the file that i want to process i used the File field to return the location of the file. My problem begins here when I click on the browse it show me my harddrive and I slect the file and it show up in the window "C:\test1.xls". however when I press the button to process the it returns an error telling me that the file cannot be found. I did a little testing and found out that even though ...

  1. #1

    Default File Field

    I am coding a ASP to process a excel file and output the
    reults to a text file. To browse for the file that i want
    to process i used the File field to return the location of
    the file. My problem begins here when I click on the
    browse it show me my harddrive and I slect the file and it
    show up in the window "C:\test1.xls". however when I press
    the button to process the it returns an error telling me
    that the file cannot be found. I did a little testing and
    found out that even though I am selecting the file from my
    hardrive it is looking for it in the c drive of the server
    Same thing happen when I write the text file. it save it
    to the server not to my PC
    Any help would be appreciated
    Thanks
    Eddy Guest

  2. #2

    Default Re: File Field

    An HTML "input type=File" form field is used for UPLOADING files TO the
    server, not downloading files FROM the server. Therefore, when you click the
    Browse button, it shows the files on the local client machine. There is
    nothing that can be done to change this. To browse files on the server for
    DOWNloading, you would need to write an ASPX page that shows the files in a
    given directory, with a hyperlink on each file name to download the file.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    http://www.takempis.com
    The more I learn, the less I know.

    "Eddy" <com> wrote in message
    news:0db401c36ca0$59123b00$gbl... 


    Kevin Guest

  3. #3

    Default Re: File Field

    The file must first be uploaded to the server in order for the script to
    process it.
    Security restricts access to client side files.

    I suggest you break this into a few steps:
    1) Pick the file from the client PC
    2) Upload to the server
    3) Server processes it and saves a text file to the Server.
    4) User gets a link presented to them so they can then download the file to
    their PC.

    hope that helps,
    -fs


    "Eddy" <com> wrote in message
    news:0db401c36ca0$59123b00$gbl... 


    Francis Guest

  4. #4

    Default Re: File Field

    Sorry Eddy, I'm afraid I'm completely confused.
    What do you mean by "unload" ?

    "Eddy" <com> wrote in message
    news:0e4e01c36cac$bfa80460$gbl... 
    > for the script to 
    > Server. 
    > download the file to [/ref]
    > want [/ref]
    > of [/ref]
    > it [/ref]
    > press [/ref]
    > and [/ref]
    > my [/ref]
    > server 
    > >
    > >
    > >.
    > >[/ref][/ref]


    Francis Guest

  5. #5

    Default Re: File Field

    Bah!

    There is a fundamental misunderstanding at work here, Eddy.

    Your browse control just gives a String, say c:\myfile to your server. Your
    server is using that to try and load a file. However, that file is not on
    your server. Like Francis said, you need to GET THE FILE TO THE SERVER
    before you can load it at your server.

    So follows the steps Francis set out and you may get somewhere.

    HTH,

    Tom

    "Eddy" <com> wrote in message
    news:0db401c36ca0$59123b00$gbl... 


    Tom Guest

  6. #6

    Default Re: File Field

    ok, I want my program to read this excel file that i have
    on my local PC, when i click browse on my app , it show me
    the open dialog box and I select the file that is on my
    local PC, then I click ok and the path to the file is
    diaplayed on the File field "c:\test1.xls"
    when I click on the process file , my code should read
    that file from my local PC however, the program ends up
    looking at the c: drive on the web server so of course it
    tell me that it cannot find the file. How do i tell it the
    path diaplayed is on my local PC and not on the web server 
    >> for the script to 
    >> Server. 
    >> download the file to [/ref][/ref]
    the 
    >> want [/ref][/ref]
    location [/ref][/ref]
    and 
    >> press [/ref][/ref]
    telling me 
    >> and [/ref][/ref]
    from 
    >> server [/ref][/ref]
    save it [/ref]
    >
    >
    >.
    >[/ref]
    Eddy Guest

  7. #7

    Default Re: File Field

    Eddy, you can't do that.
    The web server can only access IT's disk.
    The reason is security.
    If a web server could access the disk of all those who browse it, there'd be
    chaos.
    Sorry, see my earlier email for the steps you should follow.
    Hope that helps,
    regards,
    -Francis Shanahan

    "Eddy" <com> wrote in message
    news:024001c36cb3$6231ea10$gbl... [/ref]
    > the [/ref]
    > location [/ref]
    > and [/ref]
    > telling me [/ref]
    > from [/ref]
    > save it 
    > >
    > >
    > >.
    > >[/ref][/ref]


    Francis Guest

  8. #8

    Default Re: File Field



    I've got the same question as Eddy. How do you go about uploading the
    file from the local pc to the Web Server. We have the 'file' type input
    control that shows the client side location of the file after browsing
    to it. When clicking submit, how do you go about pulling/reading the
    file in from the client pc? THAT is what eddy as well as myself are
    asking.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Clint Guest

  9. #9

    Default Re: File Field

    It's way too easy...

    Create an "upload" button. When the user clicks it, fire this code:

    If Not (fileFiled.PostedFile Is Nothing) Then
    Try
    ' This actually uploads the file and saves it on the server
    fileField.PostedFile.SaveAs("c:\folder\file.txt") ' Any path
    you want here. Make sure you have write access.

    Catch exc As Exception
    ' error handling code here.

    End Try
    End If

    Good Luck,

    Chris

    Christopher Campbell
    mailto:com

    "Clint Jennings" <com> wrote in message
    news:phx.gbl... 


    Christopher Guest

  10. #10

    Default Re: File Field

    Also look here
    (ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemWebUIHtmlControlsHtm
    lInputFileClassPostedFileTopic.htm)

    in the framework docs

    "Christopher Campbell" <com> wrote in message
    news:phx.gbl... 
    path 
    >
    >[/ref]


    Tom Guest

  11. #11

    Default Re: File Field

    Clint,
    this is surprisingly easy with asp.net
    Here's an article describing the entire process
    http://www.ondotnet.com/pub/a/dotnet/2002/04/01/asp.html
    and here's the code I myself have used and know works:

    Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Submit1.ServerClick

    If Not File1.PostedFile Is Nothing And
    File1.PostedFile.ContentLength > 0 Then
    Try
    Dim fn As String =
    System.IO.Path.GetFileName(File1.PostedFile.FileNa me)
    Dim SaveLocation As String = "c:\inetpub\wwwroot"

    File1.PostedFile.SaveAs(SaveLocation)
    Response.Write("The file has been uploaded.")
    Catch Exc As Exception
    Response.Write("Error: " & Exc.Message)
    End Try
    Else
    Response.Write("Please select a file to upload.")
    End If
    End Sub

    regards.
    -Francis Shanahan

    "Clint Jennings" <com> wrote in message
    news:phx.gbl... 


    Francis Guest

Similar Threads

  1. attachment or file in db2 field
    By min tin in forum Coldfusion Database Access
    Replies: 1
    Last Post: January 19th, 09:40 AM
  2. File Field Confusion
    By NMedina in forum Dreamweaver AppDev
    Replies: 1
    Last Post: March 15th, 01:18 PM
  3. file field
    By atse in forum ASP
    Replies: 4
    Last Post: October 17th, 08:59 PM
  4. File Field Control
    By Anne in forum ASP.NET General
    Replies: 2
    Last Post: July 30th, 03:43 PM
  5. Insert a file in a SQL field
    By Jacco Schalkwijk in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 3rd, 09:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139