Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2004, 11:37 AM
Authorized User
 
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default Text getting cleared after file upload

My file upload is working fine. The problem is after the file is uploaded, the text box containing the file name is cleared. I also want to save this filename to the database. Since, it is getting cleared it is not displayed on the page and I cannot add it to the database.

Thanks


 
Old August 27th, 2004, 12:30 AM
Authorized User
 
Join Date: Feb 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mahulda
Default

Make sure that the EnabledViewstate property of the textbox is set to True.


-.. -..
 
Old August 27th, 2004, 07:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You would want to grab the file name as it is being uploaded (when the user click 'upload' save the file name to the DB).

 
Old August 27th, 2004, 08:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I am assuming that you have this fileupload set to runat="server"??

You should be able to get the file name with path using:

[FileUploadName].PostedFile.FileName

You can get just the file name without the path using:

System.IO.Path.GetFileName([FileUploadName].PostedFile.FileName)

--------------------------------------

You can then use this during your post when you add other items / save the file.

J
 
Old August 30th, 2004, 10:26 AM
Authorized User
 
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mahulda-
It is not actually a textbox. It is defined with <INPUT> tag ang type=file. So, it does not have the property you are talking about.

Katsarojs and stu9820-
I am using postedfile.filename to get the file name. But, like I said, as soon as I click on upload button, the file name in the box is cleared. I tried declaring a public variable and assigning the file name to it during the upload process. But, when I try to use that variable in other subprocedure, it contains nothing. If I can stop clearing of the input box, I will be able to use it's value also.
 
Old August 30th, 2004, 10:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Can you post your code?

 
Old August 30th, 2004, 11:17 AM
Authorized User
 
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the code for upload button followed by the update button

Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click

        Dim sPath As String
        Dim sFile As String

        Dim sSplit() As String
        Dim sPathFriendly As String
        Dim MsgText As String

        'Upload to same path as script
        'Internet Anonymous User must have write permissions

        sPath = Server.MapPath(".")
        If Right(sPath, 1) <> "\" Then
            sPathFriendly = sPath 'Friendly path name for display
            sPath = sPath & "\"
        Else
            sPathFriendly = Left(sPath, Len(sPath) - 1)
        End If

        'Save as same file name being posted
        'The code below resolves the file name
        '(removes path info)
        sFile = txtPDFfile.PostedFile.FileName
        sSplit = Split(sFile, "\")
        sFile = sSplit(UBound(sSplit))

        sFullPath = sPath & sFile
        Try
            txtPDFfile.PostedFile.SaveAs(sFullPath)
            MsgText = "File uploaded!"
        Catch Ex As Exception
            MsgText = "Upload of File " & sFile & " to " & sPathFriendly & " failed for the following reason: " & Ex.Message
        End Try

    End Sub






In the update_button click, look for the bold lines:-



Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        Dim strConn As String = "data source=PCIASERV;packet size=4096;user id=sa;password='blue';persist " & _
         "security info=False;initial catalog=TestPubs"


        Dim Jname As String = txtJurisName.Text
        Dim JState As String = lstState.SelectedValue
        Dim JZip As String = txtJurisZip.Text
        Dim Jwebsite As String = txtWebsite.Text
        Dim CName As String = txtContactName.Text
        Dim CPhone As String = txtContactPhone.Text
        Dim cphoneExtn As String = txtExtn.Text
        Dim cemail As String = txtContactEmail.Text
        Dim MAction As String = txtMaction.Text
                        :
                        :
        Dim LastModby As String = Me.Session("User")
        Dim LastModDate As Date = Now()
        Dim pdffile As String


        'pdffile = Request.Files(0).FileName

        pdffile = txtPDFfile.PostedFile.FileName Dim urllink As String
        urllink = txtURL.Text

        Dim cmd As New SqlCommand("UPDATE tbl_jurisdiction SET JState='" & JState & "',JZip='" & JZip & "',JWebsite= '" & Jwebsite & "',CName= '" & CName & "',CPhone = '" & CPhone & "',CphoneExtn= '" & cphoneExtn & "',CEmail= '" & cemail & "',WorkDate= '" & WorkDate & "',HearingDate= '" & HearingDate & "',AdoptionDate= '" & AdoptionDate & "',IntroductionDate = '" & IntroductionDate & "',Status= '" & Status & "',SubmittedBy= '" & SubmittedBy & "',MDate= '" & Mdate & "',MComments= '" & Mcomments & "',OText= '" & OText & "',OHistory= '" & OHistory & "',PCIAAction = '" & PCIAAction & "',MAction= '" & MAction & "',JType = '" & Jtype & "',Consultant= '" & Consultant & "',LastModby = '" & LastModby & "',LastModDate='" & LastModDate & "',URLLink='" & urllink & "' where JNAME = '" & Jname & "'", New SqlConnection(strConn))

        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
        Server.Transfer("AllOrdinances.aspx")
    End Sub

 
Old September 3rd, 2004, 04:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Renu,

Did you try declaring sFile or sFullPath as global and use the same within btnUpdate_Click? Or how about setting value attribute of txtPDFfile within the Upload_click?

Does that help?

_________________________
- Vijay G
Strive for Perfection
 
Old September 6th, 2004, 09:43 PM
Authorized User
 
Join Date: Aug 2004
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did try creating a global variable and declared it as public, but that didn't help. But this is how I got around the problem. I declared a hidden textbox and stored the value of the file name. I can get the value later in my update_click method. I have found out that with type=file, the file does get cleared after the upload. This is the only way to get the file name.
But, thankyou all for looking into the problem.


_________________________
- Vijay G
Strive for Perfection
[/quote]

 
Old September 7th, 2004, 09:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Actually, that isn't the only way to get the file name. I implemented the method I described to you less than 2 weeks ago...

J





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to upload small text file from within my vb6 f method Beginning VB 6 1 April 19th, 2006 01:17 PM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
Upload a Text file from a Web Client to SQL Server petercyriljones Classic ASP Professional 0 May 20th, 2005 10:26 AM
Script to upload text file to SQL with errors ss2003 Beginning PHP 2 March 10th, 2004 12:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.