File Upload Problem - old file replaced by new file with same file name!

Hi Everyone,

I was grateful to be able to download the code for uploading files into a folder from Sreedhar's web page. The code works well, but whenever there is another new file with the same file name being uploaded into the destination folder, the old file will be replaced. I am wondering if there is any way to solve this problem (How about adding a number to the new file's name, e.g. File1.doc, if there is an existing File.doc?) I am an absolute beginner and any help is deeply appreciated.

The original code is as follows:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If (FileUpload1.HasFile) Then

Dim fileName As String = FileUpload1.FileName

FileUpload1.SaveAs("c:\temp\" & fileName)

UploadStatusLabel.Text = "Your file was saved as " & fileName

Else

UploadStatusLabel.Text = "Please provide a file to upload."

End If

End Sub

</script>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

<asp:FileUpload ID="FileUpload1" runat="server" />

<br />

<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />

<br />

<asp:Label ID="UploadStatusLabel" runat="server" Text=""></asp:Label>

</asp:Content>


Many thanks,

Tan

0
tanhc
10/30/2005 8:46:10 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

19 Replies
2481 Views

Similar Articles

[PageSpeed] 19

hello.

before saving the file use the File  class to see if there's a file with the same name. the following example is simple but it may not work very well if you have several uploads done at the same time :

int i = 0;
string path = @"c:\Temp\" + filename
while( File.Exists(  path ) ) //verify if file exists
{
   path = path + i.ToString();
   i++;
}

//here path should have a unique name (though this algorythm is not thread safe - regarding the name of the file)
//so you can just put the rest of the code here to save the file

btw, if i were you, i'd use a GUID as a filename because this will make it easier to garantee that there aren't 2 files with the same name (using guig will normally make you have to maintain a record for each file on a db)
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
0
Luis
10/30/2005 9:50:15 PM

Hi Luis,

Thank you very much. However, it seems that your code is in C#, which I am not familiar withSad [:(] Could you please convert it into Visual Basic code for me???

Furthermore, could you also show me what is GUID and how it can be used in uploading file?? I think GUID may be the right solution I should use for my little program.

Many thanks,

Tan

0
tanhc
10/31/2005 5:27:10 AM

private function GetFileName(filename as string) as string
    dim i as integer = 0
    dim path as string = "c:\Temp\" & filename
    do while File.Exists(path)
       path = path & i.ToString()
    loop
    return path
end function

If (FileUpload1.HasFile) Then
    Dim fileName As String = GetFileName(FileUpload1.FileName)
    FileUpload1.SaveAs(
filename)
    UploadStatusLabel.Text =
"Your file was saved as " & fileName
Else
    UploadStatusLabel.Text = "Please provide a file to upload."
End If

 


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
10/31/2005 11:51:57 PM
Hi Brian,

I get the error saying that: Name 'file' is not declared. I tried to add a line: Dim file As String as an attempt to solev the problem but it didn't work. Please help!!! Smile [:)]

Many thanks,

Tan
0
tanhc
11/1/2005 12:11:04 PM
hello.

you must import the system.io namespace. if you're putting those lines on the aspx page you must add this:
<%@ Import Namespace="System.IO"%>


--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
0
Luis
11/1/2005 12:48:35 PM
Hi there,

Many thanks for the helps from Luis and Brian first...

The code works now. But, I noticed that whenever I tried to upload a file (regardless whether there is any file with similar file name), two copies of the file would be uploaded! This means that if I am uploading a file called ABC.pdf, the program would upload an ABC.pdf as well as creating an ABD.pdf0 in c:\temp even the c:\temp\ is empty. Any suggestion to solve the problem? Smile [:)]

By the way, because the program will add an '0' to the end of the file extension (i.e. ABC.pdf0 instead of renaming it to 0ABC.pdf), I got a little problem to open the file. I tried to solve this problem by changing the path = path & i.ToString()   to path = path & i.ToString() & filename. This creates a long a funny file names, such as ABC.pdf.ABC.pdf in c:\temp\. Any better way to sort this out?

Regards,

Tan

0
tanhc
11/1/2005 3:10:27 PM
Can you post the exact code you are using.
Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
11/1/2005 7:21:12 PM
My apologies Embarrassed [:$]. After I recopied the code and pasted onto a new .aspx page, the function did no longer create two files in one shot. However, I still do not manage to solve the problem where a "0" is placed at the end of the uploaded file's extension if similar file name exists. Any idea how to get this sorted out? Many thanks.

The codes is as follows:


<%@ Page Language="VB" %>

<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">

Private Function GetFileName(ByVal filename As String) As String

Dim i As Integer = 0

Dim path As String = "c:\Temp\" & filename

Do While File.Exists(path)

path = path & i.ToString()

Loop

Return path

End Function

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If (FileUpload1.HasFile) Then

Dim fileName As String = GetFileName(FileUpload1.FileName)

FileUpload1.SaveAs(filename)

UploadStatusLabel.Text = "Your file was saved as " & fileName

Else

UploadStatusLabel.Text = "Please provide a file to upload."

End If

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:FileUpload ID="FileUpload1" runat="server" /><br />

<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />&nbsp;<br />

<asp:Label ID="UploadStatusLabel" runat="server" Text=""></asp:Label></div>

</form>

</body>

</html>

0
tanhc
11/2/2005 8:36:21 PM

change the function to:-

Private Function GetFileName(ByVal filename As String) As String

Dim i As Integer = 0

Dim path As String = "c:\Temp\" & filename
dim fname as string = path.substring(0, path.indexof("."))
dim ext as string = path.substring(path.indexof("."))

Do While File.Exists(path)

path = fname & i.ToString() & ext

Loop

Return path

End Function


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
11/2/2005 10:17:01 PM
hello.

i'm no vb.net expert, but shouldn't it be dim i as string?
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
0
Luis
11/3/2005 3:20:17 PM
lol that was a conversion from your c# code but you do want to be easily able to increment it and as an integer it's more easily done then calling the tostring method allows you to append it. I always have Option Strict on but if it isn't on it will probably work without the tostring. Not a good practice though.
Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
11/3/2005 8:20:56 PM

Hi there,

The program works, but if I upload the same file for the 3rd time, my computer hang...Sad [:(]

By the way, I had created a table called UploadFileTbl and would like to save the name of the file uploaded automatically into the table so that I can create a webpage for people to download the file. However, even though I know that this can be done, but I dont know how to do it. The table has only two columns, i.e. FileID (Primary, int) and Filename (Varchar). Can someone please enlighten me??

Many thanks

Tan

0
tanhc
11/6/2005 8:35:08 AM

Private Function GetFileName(ByVal filename As String) As String

Dim i As Integer = 0

Dim path As String = "c:\Temp\" & filename
dim fname as string = path.substring(0, path.indexof("."))
dim ext as string = path.substring(path.indexof("."))

Do While File.Exists(path)

i += 1
path = fname & i.ToString() & ext

Loop

Return path

End Function

I forgot to increment the i variable. As far as your table goes you haven't said how much you know about accessing databases. Are you saying you need to know from scratch how to access a database and update a table?


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
11/6/2005 6:09:09 PM

Hi Brian,

Thank you very much for your help. I really sorry for being slow in replying to your message as I was suffering from cold for a week and then was tied up with some other chores...Sad [:(] Anyway, I did do my home work and have learnt a bit more about how to insert data into tables.

I learned to write the codes to show User Name of the current logged in user in a text box (i.e. TextBox1.Text = User.Identity.Name()). However, my trial to insert the user name of the person who logged in automatically into a table without requiring him to retype his username still show no success. The codes are shown below. Is this a right/viable way?? Any suggestion?

Thanks in advance.

Regards,

Tan


<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Upload_files.aspx.vb" Inherits="Upload_files" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="mainContentHolder" Runat="Server">

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" InsertCommand="INSERT INTO [Gallery] ([UploadedByMemberName], [FixtureID], [Notes], [PictureURL]) VALUES (@UploadedByMemberName, @FixtureID, @Notes, @PictureURL)" OldValuesParameterFormatString="original_{0}" >

<InsertParameters>

<asp:Parameter Name="UploadedByMemberName"

DefaultValue=User.Identity.Name()

Type="String" />

<asp:ControlParameter Name="FixtureID"

ControlID="FixtureIDtextBox"

Type="Int32" />

<asp:ControlParameter Name="Notes"

ControlID="TextBoxNotes"

PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="PictureURL"

ControlID="FileUpload1"

PropertyName="FileName"

Type="String" />

</InsertParameters>

</asp:SqlDataSource>

Upload your photo from matches

<br />

<br />

Please select the photo:

<asp:FileUpload ID="FileUpload1" runat="server" /><br />

<br />

Uploaded by:&nbsp;<asp:Label ID="Label1" runat="server"></asp:Label>

<br />

<br />

Fixture ID:

<asp:TextBox ID="FixtureIDtextBox" runat="server"></asp:TextBox><br />

<br />

Comments:<asp:TextBox ID="TextBoxNotes" runat="server"></asp:TextBox><br />

<br />

<asp:Button ID="Button1" runat="server" Text="Upload" /><br />

<asp:Label ID="FileUploadReport" runat="server"></asp:Label><br />

<br />

<br />

</asp:Content>



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

Partial Class Upload_files

Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

If FileUpload1.HasFile Then

Try

FileUpload1.SaveAs("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\Beta3\Photos\" & _

FileUpload1.FileName)

Catch ex As Exception

FileUploadReport.Text = "Failed because: <br/>" & ex.Message

End Try

FileUploadReport.Text = "File uploaded to Beta3 from <br/>" & _

FileUpload1.PostedFile.FileName

SqlDataSource1.Insert()

Else

FileUploadReport.Text = "Please select a file before clicking " & _

"the 'Upload' button"

End If

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim UName As String = User.Identity.Name()

Label1.Text = UName.ToString

End Sub

End Class

0
tanhc
11/20/2005 11:57:14 PM
The best way is to remove this:- DefaultValue=User.Identity.Name()
and overide the inserting event of the sqldatasource. Then set the value of the parameter

e.Command.Parameters("UploadedByMemberName").Value = User.Identity.Name()


Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
11/21/2005 12:40:16 AM

Hi Brian,

It's me again Smile [:)] I had removed the
DefaultValue=User.Identity.Name() and added the e.Command.Parameters("UploadedByMemberName").Value = User.Identity.Name() to the aspx.vb file. I dont know exactly how to override the inserting event of the sqldatasource. I tried with some combinations and none worked. Mind to help to to check what's wrong there? Thanks in advance...

Regards,

Tan



Page
Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Upload_files.aspx.vb" Inherits="Upload_files" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="mainContentHolder" Runat="Server">

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" InsertCommand="INSERT INTO [Gallery] ([UploadedByMemberName], [FixtureID], [Notes], [PictureURL]) VALUES (@UploadedByMemberName, @FixtureID, @Notes, @PictureURL)" OldValuesParameterFormatString="original_{0}" >

<InsertParameters>

<asp:Parameter Name="UploadedByMemberName"

Type="String" />

<asp:ControlParameter Name="FixtureID"

ControlID="FixtureIDtextBox"

Type="Int32" />

<asp:ControlParameter Name="Notes"

ControlID="TextBoxNotes"

PropertyName="Text"

Type="String" />

<asp:ControlParameter Name="PictureURL"

ControlID="FileUpload1"

PropertyName="FileName"

Type="String" />

</InsertParameters>

</asp:SqlDataSource>

Upload your photo from matches

<br />

<br />

Please select the photo:

<asp:FileUpload ID="FileUpload1" runat="server" /><br />

<br />

Uploaded by:&nbsp;<asp:Label ID="Label1" runat="server" Visible="False"></asp:Label>

<br />

<br />

Fixture ID:

<asp:TextBox ID="FixtureIDtextBox" runat="server"></asp:TextBox><br />

<br />

Comments:<asp:TextBox ID="TextBoxNotes" runat="server"></asp:TextBox><br />

<br />

<asp:Button ID="Button1" runat="server" Text="Upload" /><br />

<asp:Label ID="FileUploadReport" runat="server"></asp:Label><br />

<br />

<br />

</asp:Content>



......................................................................................................................................................

Partial Class Upload_files

Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

If FileUpload1.HasFile Then

Try

FileUpload1.SaveAs("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\Beta3\Photos\" & _

FileUpload1.FileName)

Catch ex As Exception

FileUploadReport.Text = "Failed because: <br/>" & ex.Message

End Try

FileUploadReport.Text = "File uploaded to Beta3 from <br/>" & _

FileUpload1.PostedFile.FileName

SqlDataSource1.Insert()

Else

FileUploadReport.Text = "Please select a file before clicking " & _

"the 'Upload' button"

End If

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim UName As String = User.Identity.Name()

Label1.Text = UName.ToString

End Sub

Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs)

e.Command.Parameters("UploadedByMemberName").Value = User.Identity.Name()

End Sub

End Class

0
tanhc
11/21/2005 8:36:28 PM
If you are using Visual Web Developer it's simple enough. In the code view select the sqldatasource1 in the dropdownlist on the top left, then select the inserting event (not inserted) from the top right dropdownlist. These events make sense if you think about them. The inserted event will happen after the data has been inserted in the database by the sqldatasource and the inserting event just before the data is inserted so you want to set the parameters before the data is inserted hence you overide the inserting event.
Brian O'Connell (MCAD) - http://www.systemdotweb.com
0
BrianOConnell
11/22/2005 6:49:51 PM
Hi Brian,

Thank you for telling me how to use that feature of VWD!!! That is one of the most important thing I learned from this forum. Now the automatic add username into the database function works smoothly. Thank you very much!!! Will start troubling you and everyone in this forum again in case I got any problem.

Regards,

Tan

p/s: The e.Command.Parameters("UploadedByMemberName").Value = User.Identity.Name() should be e.Command.Parameters("@UploadedByMemberName").Value = User.Identity.Name()

0
tanhc
11/30/2005 5:21:30 PM

Hi Brian,

 

I modified some of the codes written by you (i.e. for the handling of duplicate filenames) for uploading multiple files. I tried to write the codes to save the ‘real’ file name of the file uploaded (which might be modified if the file name duplicates) into a table. However, I found that my code got a bug, i.e. if the file uploaded is saved as File2.doc in a folder, my code will record the file name as File3.doc into the table instead of File2.doc. How to solve this problem?

 

Many thanks

 

The codes is as follows:

 

<%@ Page Language="VB" %>

<%@ Import Namespace="System.IO" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<script runat="server">

   

    Private Function GetFileName(ByVal filename As String) As String

      

        Dim i As Integer = 0

        Dim path As String = "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\WebSite3AddFiles\Documents\" & "#" & filename

        Dim fname As String = path.Substring(0, path.IndexOf("."))

        Dim ext As String = path.Substring(path.IndexOf("."))

 

        Do While File.Exists(path)

            i += 1

            path = fname & i.ToString() & ext

        Loop

 

        Return path

 

    End Function

   

   

    Protected Sub uploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

       

        If (FileUpload1.HasFile) Then

            Dim fileName As String = GetFileName(FileUpload1.FileName)

            FileUpload1.SaveAs(fileName)

        End If

       

        If (FileUpload2.HasFile) Then

            Dim fileName As String = GetFileName(FileUpload2.FileName)

            FileUpload2.SaveAs(fileName)

        End If

       

        If (FileUpload3.HasFile) Then

            Dim fileName As String = GetFileName(FileUpload3.FileName)

            FileUpload3.SaveAs(fileName)

        End If

 

        SqlDataSource1.Insert()

    End Sub

   

   

    Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)

        If FileUpload1.HasFile Then

            Dim savedpath As String = GetFileName(FileUpload1.FileName)

            Dim filenameOnly As String = savedpath.Substring(savedpath.IndexOf("#"))

            e.Command.Parameters("@doc1").Value = filenameOnly.ToString

        End If

       

        If FileUpload2.HasFile Then

            Dim savedpath As String = GetFileName(FileUpload2.FileName)

            Dim filenameOnly As String = savedpath.Substring(savedpath.IndexOf("#"))

            e.Command.Parameters("@doc2").Value = filenameOnly.ToString

        End If

       

        If FileUpload3.HasFile Then

            Dim savedpath As String = GetFileName(FileUpload3.FileName)

            Dim filenameOnly As String = savedpath.Substring(savedpath.IndexOf("#"))

            e.Command.Parameters("@doc3").Value = filenameOnly.ToString

        End If

    End Sub

   

</script>

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"

            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [SuggestionTable] WHERE [sugestionID] = @original_sugestionID AND [suggestion] = @original_suggestion AND [doc1] = @original_doc1 AND [doc2] = @original_doc2 AND [doc3] = @original_doc3 AND [submittedByUser] = @original_submittedByUser"

            InsertCommand="INSERT INTO [SuggestionTable] ([suggestion], [doc1], [doc2], [doc3], [submittedByUser]) VALUES (@suggestion, @doc1, @doc2, @doc3, @submittedByUser)"

            OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [sugestionID], [suggestion], [doc1], [doc2], [doc3], [submittedByUser] FROM [SuggestionTable]"

            UpdateCommand="UPDATE [SuggestionTable] SET [suggestion] = @suggestion, [doc1] = @doc1, [doc2] = @doc2, [doc3] = @doc3, [submittedByUser] = @submittedByUser WHERE [sugestionID] = @original_sugestionID AND [suggestion] = @original_suggestion AND [doc1] = @original_doc1 AND [doc2] = @original_doc2 AND [doc3] = @original_doc3 AND [submittedByUser] = @original_submittedByUser" OnInserting="SqlDataSource1_Inserting">

            <InsertParameters>

                <asp:ControlParameter ControlID="TextBox1" Name="suggestion" PropertyName="Text" Type="String" />

                <asp:ControlParameter ControlID="FileUpload1" Name="doc1" PropertyName="FileName" Type="String" />

                <asp:ControlParameter ControlID="FileUpload2" Name="doc2" PropertyName="FileName" Type="String" />

                <asp:ControlParameter ControlID="FileUpload3" Name="doc3" PropertyName="FileName" Type="String" />

                <asp:Parameter Name="submittedByUser" Type="String" />

            </InsertParameters>

        </asp:SqlDataSource>

        &nbsp;</div>

        <br />

        <table style="width: 800px">

            <tr>

                <td style="width: 100px">

                </td>

                <td width="700">

                </td>

            </tr>

            <tr>

                <td style="width: 100px; height: 132px">

                    Suggestion:</td>

                <td style="height: 132px" width="700">

                    <asp:TextBox ID="TextBox1" runat="server" Height="120px" TextMode="MultiLine" Width="540px"></asp:TextBox></td>

            </tr>

            <tr>

                <td style="width: 100px">

                    Relevant Doc:

                </td>

                <td width="700">

                    <asp:FileUpload ID="FileUpload1" runat="server" /></td>

            </tr>

            <tr>

                <td style="width: 100px">

                </td>

                <td width="700">

                    <asp:FileUpload ID="FileUpload2" runat="server" /></td>

            </tr>

            <tr>

                <td style="width: 100px; height: 19px;">

                </td>

                <td width="700" style="height: 19px">

                    <asp:FileUpload ID="FileUpload3" runat="server" /></td>

            </tr>

            <tr>

                <td style="width: 100px">

                </td>

                <td width="700">

                    <asp:Button ID="uploadButton" runat="server" Text="Upload" OnClick="uploadButton_Click" /></td>

            </tr>

        </table>

    </form>

</body>

</html>

 

0
tanhc
12/1/2005 4:24:21 PM
Reply:

Similar Artilces:

to file:// or not to file://
(Firefox 1.5.0.6) I'm having trouble with HTML Anchors (links) using the file: protocol. The URL I'm trying to get at looks something like this file://///Host.Domain/Share/Dir1/Dir2/File.Ext If I click on the link, /nothing/ happens but, if I "Copy Link Location" and paste exactly the same thing into the "address bar" in FireFox, FireFox is perfectly happy to show me the file. Why the difference? Am I tripping over some security restriction here? Any suggestions? TIA, Phill W. Phill W. wrote: > (Firefox 1.5.0.6) > I'm ...

Get file name of uploaded file
Hello,  Is there a way to grab the full name of the file that is being uploaded?  The software automatically changes it when uploading. Thanks, Michael Michael,If you are using the FileUpload control you can use the PostedFile.FileName property.  If you need just the name and not the path, you can use Path.GetFileName(fileControl.PostedFile.FileName) Is this what you are looking for? ~Ben Thanks Ben, but have you ever looked at the Classified Starter kit?  It does not use the FileUpload control. Michael,I have not. What is the control that it is using? Is it...

File name inserting as NULL instead of actual file name after file is uploaded to server
I have a form that a user makes a selection from a drop down list and uploads a file.   Once the file is uploaded to the server, I also do an insert into a sql database to get the value from the dropdown list and ideally, the name of the file they uploaded.   However, I can't figure out how to grab the name of the file after it has been uploaded and include it in the insert.    Here's my vb.net code behind where I get the file and do the insert.    How can I grab the name of the file, and insert it into the "UploadTitle" fie...

File name of uploaded file.
I'm using this routine to upload a file to the server.  'Filebox.PostedFile.FileName' contains the full path from the user's desktop e.g. C:\Documents and Settings\evanburen\Desktop\myfile.doc.  How can I grab just the filename itself e.g. myfile.doc?  Thanks.Dim TheFile As String = FileBox.PostedFile.FileName        If TheFile.Length > 0 Then                          Dim FilePath As String = MapPath("") + "\attachments\"...

How to get a file type name from the uploading file?
Ex. i m uploading a file name from path c:\inetpub\wwwroot\rt\images\product\cat.txt how can i get "txt" from this path when uploading? Thank you. System.IO.Path.GetExtension(filename) -> ".txt"Lostinet (Li Jian Dai) .NET MVP http://www.lostinet.com/ for LWTree/DatePicker http://www.contextboundmodel.net/ for AOP.NET...

upload file by file
hi all,   we have project, local in server, more then one people do the update, let's say, if all file local in test, I did the modify in local and build and upload the whole test file into service, it work fine. but if I only upload helloone.aspx. and its Vb file (under test) into service, it did not work( the VB code) , is that a way to only upload file by file to service, thank you   If I understand your problem correctly, I think the problem that you may be having is that after pages are compiled locally they are not being compiled for the entire site.  I would su...

File Upload
Hey I've got a fileUpload control on an aspx page that works fine for the accepted file type, .rpts, and brings up the correct error message for not allowed extensions such as .exes and .jpgs. But .pdf files should cause an error message to be displayed, as only .rpt files are allowed to be uploaded, but instead it brings up a blank page like a web500 page. Is there a known bug when attempting to upload pdf's?   Just in case,here's the only relevant code attached to the control:   If uploadFilename.EndsWith(".rpt") = True Then 'ensures only .rp...

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

replace existing uploaded file with new file on server
hi,I am working with Asp.net2.0,C#.net. i am uploading resume doc to the server.   requirement is:   eg: i uploaded resume.doc file to the server.(this is done)if i upload another file(newresume.doc) it has to replace the existing file(resume.doc) on the server.and i have to concatinate userid to the filename to differentiate from other userdocument.thenonly there will not be any ambiguity between files if 2 users uploded files with same name.      i am uploading(uploadeddata folder on server) like this.    //button_click  bool fileOK =...

Eof of file , file read and file write ! Problem !
Hello All, I want to do 2 things. I have a big file and I want to read file line by line upto last. and side by side i want to write it to new file with some change I am not getiing , in a read , linemode! how i will get End of file and how i will do all this. can you tell me script. I'm not sure I understand your question. From the PowerBuilder Help file, in linemode! FileRead() will return a 0 when it reaches End of File (EOF) so it should be trivial to code? This is just off the cuff but I would imagine it's something like li_Readfile = FileOpen( ...

how to avoid same name file replacement when uploading a file in web?
 I used the following code to upload the file and its working properly.But if i upload same name files twice its replacing and both having different  content.How to solve this problem.I want to upload both files in to the same folder? f FileUpload1.HasFile Then            Try                Label1.Text = "Uploading File " + FileUpload1.FileName                FileU...

File Uploading
I have a distributed application that retrieves a file from the client form into a byte array, then passes that byte array to a web service which then writes the byte array to a file to a remote server. The problem is that the files appear to be getting randomly corrupted, sometimes they get uploaded fine, others don't. The total bytes of the files appears correct, but somehow they get all jumbled. Here's the code that retrieves the file on the client: Dim NewFile As HttpPostedFile = FileUpload.PostedFile Dim f As New FileInfo(NewFile.FileName) Dim fStre...

file upload change file name
Hi all,I want to change file name when fileupload is uploading.For example the file name is "bahadir.jpg" then I want to change "bahadir_00231.jpg"how to do this? Good works. Humans coded by "DNA" language. Use FileUpload.SaveAs()"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us." I think you can use this in you button click event where the StrFileName you can create by code UploadControl.PostedFile.SaveAs(Server.MapPath(StrFileName)) hope thi...

File name in the file upload control
Hi everyone, Im using file upload control to upload files, on clicking browse button, a dialog box open and selecting the file and "Open". it shows the file path...as C:\Documents and Settings\con_ksprakash\Desktop\mail.doc      only half of the path is visible so, either it has to show text right align focus or i want to display only the file name to user. is it possible ?   thanks in advance.ThanksPrakash.K.S hi, you only want to show the "mail.doc" from fileupload control? as i know, that is not possible, because fileupl...

How to get file extension of uploaded file
Heres a simlpe one. How do i get the file extension of an uploaded file or any file for that matter without using any of the substring or split functions. I thought File.PostedFile would contain a property like that but it was not to be. Thanks in advance. As far as I know, the only way to get the extension is to parse it out...out of curiosity, why do you not want to use any of the string methods for parsing? Chris I totally agree with the previous response but thought I would add a few other options which *may* help, depending if they are usable in your situation. (Without additi...

Web resources about - File Upload Problem - old file replaced by new file with same file name! - asp.net.getting-started

STUDY: Teens Leaving Facebook, Being Replaced By More Users 55 And Older
Are Facebook users getting older on average? Very much so, according to a recent study from digital agency iStrategyLabs , which found that the ...

craigslist : Why hasn't another product disrupted and replaced Craigslist?
Answer (1 of 48): Josh Hannah argues that the premise of this question is false and that Craigslist "has been disrupted." He mistakenly confuses ...

Office Mobile - replaced by new apps on the App Store on iTunes
Get Office Mobile - replaced by new apps on the App Store. See screenshots and ratings, and read customer reviews.

Keith Moon Passes Out at the Cow Palace November 20, 1973 and is Replaced by Scott Halpin. - YouTube
I cleaned up this vid to better synch audio... Sometime during the show, Keith Moon downs a mixture of horse tranquilizers and brandy. Evidently ...

Dubai Ramadan charity campaign replaced with labourer wish list idea
This year Adopt-A-Camp’s Ramadan Care Packages appeal is not taking place but people can still help through the newly launched Project Wishlist ...

Replaced Adam Reynolds keen for answers from South Sydney Rabbitohs coach Michael Maguire
South Sydney halfback Adam Reynolds is keen for a clear-the-air meeting with coach Michael Maguire after being hooked when the game was on the ...

CEO John Chambers: Cisco has 'replaced' 30% of its managers
Cisco CEO John Chambers just shared some...

ACT poker machine target to be replaced by ratio
The number of poker machines operating in the ACT will fall in coming years, as the government replaces an aspirational target of 4000 machines ...

Charlie Cox replaced by James Morrison on Top Gear
Jazz legend James Morrison is making his small screen return as TV host following the shock departure of Top Gear Australia presenter Charlie ...

Kevin Rudd sought Hillary Clinton counsel after being replaced as prime minister
Herald Sun Kevin Rudd sought Hillary Clinton counsel after being replaced as prime minister Herald Sun KEVIN Rudd sought the sympathy of the ...

Resources last updated: 12/24/2015 10:09:49 AM