473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to upload a file in a specific directory

Hi Everyone,
can anyone please let me know how to upload a file to a specific directory. I am using ASP.NET Fileupload component. I want to allow user to upload files to a directory or a sub directory. Depending upon their choice, they can upload in any folder. How can I trace in my web application that a user is in a particular folder & the document he uploads get uploaded in the correct folder or sub folder??? Thanks.
Jan 14 '09 #1
14 3739
Actually I want to create FTP like application, where users can make, delete, rename directories & subsequently upload files in any of the directory. Any hint or help will much be appreciated. Thanks.
Jan 14 '09 #2
Curtis Rutland
3,256 Expert 2GB
Consider using a TreeView control to show your directory hierarchy. You could add some buttons to add a child directory to the selected node. And you could have a FileUpload control that will save the uploaded file to the selected directory.

If you modify this a little bit to show files, you could have a button to delete a selected file.

This isn't going to be a simple project, but it shouldn't be too hard either.
Jan 14 '09 #3
Thanks InsertAlias for your reply. I have put a TreeView control to show my main directory structure. I show the files of each directory in a GridView infront of it. However I am unable to understand, where do I put the button which create directory in the selected node and also upload files in it?? Is there a way that I can add a button in TreeView or GridView and put FileUpload as well??
Jan 14 '09 #4
Curtis Rutland
3,256 Expert 2GB
What I would suggest is adding either a CheckBoxField or a TemplateField with a Checkbox in it to your GridView. Then have a button outside the GridView that says something like "Delete All Selected Files" or something like that.

Then loop through the gridview and delete all the files that are checked.

As for the other buttons, I'd keep them outside the gridview/treeview. You can put the button to create a new directory below your treeview or something like that. And keep the FileUpload outside the gridview too.
Jan 14 '09 #5
InsertAlias, As suggested I have put a checkbox inside GridView with delete button outside, to delete all checked entries. But Itis throwing index out of range error..dont know why? unable to delete checked files.


Expand|Select|Wrap|Line Numbers
  1. Protected Sub DeleteSelected_Click(ByVal sender As Object, ByVal e As EventArgs) _
  2.             Handles DeleteSelected.Click
  3.             For Each row As GridViewRow In gvFolderItems.Rows
  4.                 ' Access the CheckBox
  5.                 Dim cb As CheckBox = row.FindControl("ProductSelector")
  6.                 If cb IsNot Nothing AndAlso cb.Checked Then
  7.                     ' Delete row
  8.                     Dim RowID As Integer = gvFolderItems.DataKeys(row.RowIndex).Value
  9.                     atLeastOneRowDeleted = True
  10.                     gvFolderItems.DeleteRow(RowID)
  11.                 End If
  12.             Next
  13.         End Sub
  14.  
  15.  
Jan 14 '09 #6
Frinavale
9,735 Expert Mod 8TB
You are probably getting the error because the row.RowIndex is larger than your gvFolderItems.DataKeys.

Before you do the following:
Expand|Select|Wrap|Line Numbers
  1. Dim RowID As Integer = gvFolderItems.DataKeys(row.RowIndex).Value
You should check that the row.RowIndex value is within limits.
Jan 14 '09 #7
How do I do that? Can you please give me some hint on the code.thanks.
Jan 14 '09 #8
Frinavale
9,735 Expert Mod 8TB
Just to recap:

You've created a TreeView that shows your file hierarchy on the left side of the page.

When a user clicks on a folder in the TreeView your application displays the files and folders found in that selected folder in a GridView.

Now since you want to let the user add and delete files you've put buttons under the GridView.

To delete files or folders, you have the user place check marks next to the things they want to delete.

When the click the Delete button your code should loop through and delete the files checked.


Your code does not currently do this.
First you should loop through your GridView's rows and check which ones have been selected. If you find a selected item, you should store the path to the selected item in an ArrayList or List(Of String). Then pass this to a new function that deletes the files/folders in that list.

After you have finished this process you should recreate the source for the GridView to display the current contents of the file selected.
Jan 14 '09 #9
Yes right, I have put checkbox in GridView so that they can select files to delete. The DELETE SELECTED FILES button is outside of GridView.

One more thing boss, how should I put a button which adds a sub-folder in a selected folder , basing on the user selection (selection from the treeview)??

Thanks.
Jan 14 '09 #10
Frinavale
9,735 Expert Mod 8TB
You're trying to do too many things at once here. Address one problem and then move to the next or we're going to get confused.

Anyways I'd lay out the screen

Expand|Select|Wrap|Line Numbers
  1.  
  2. MyTreeView       |      MyGridView w/in a scrollable Panel
  3.                  |  
  4.                  |
  5.                  |    AddFileButton      AddFolderButton       DeleteFileOrFolderButton
Or I'd place the buttons on top of the GridView


Expand|Select|Wrap|Line Numbers
  1. MyTreeView       |    AddFileButton      AddFolderButton       DeleteFileOrFolderButton
  2.                  |      MyGridView w/in a scrollable Panel
  3.                  |  
  4.                  |
Jan 14 '09 #11
sorry about that. Yes I have the exact settings in my page.
Jan 14 '09 #12



This is the screenshot of what i have done so far. But I am still unable to configure the DELETE SELECTED FILES or FOLDERS from my gridview. Please anyone can help here
Jan 15 '09 #13
Frinavale
9,735 Expert Mod 8TB
You need to retrieve the names of the files that are selected in the GridView.

Once you have the names you need to loop through them and delete the files.

After you're finished with that you need to recreate the DataSource for the GridView so that it displays the current files in the direcotry.

Expand|Select|Wrap|Line Numbers
  1. 'Will contain the names of all the files to delete
  2. Dim Dim fileNamesToDelete As New List(Of String)
  3.  
  4. For Each row As GridViewRow In gvFolderItems.Rows
  5.    'Retrieve the CheckBox for the row
  6.     Dim cb As CheckBox = row.FindControl("ProductSelector")
  7.  
  8.    'Check if the row has been selected
  9.    If cb IsNot Nothing AndAlso cb.Checked Then
  10.       Dim fileName As String = CStr(row.Cells(0).Value)'<--should be which ever cell contains the file name
  11.       fileNamesToDelete.Add(fileName)
  12.    Next
  13.  
  14.    'Now loop through the file names to delete and delete them
  15.    'After you're done this, refresh the GridView's DataSource
  16.  
Jan 15 '09 #14
Thxs Frinavale for your suggestions & help, finally I have developed the system.
Jan 19 '09 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
2
by: Terry Field | last post by:
We've recently moved an application from a W2K server to a Windows 2003 server with IIS 6.0 and in the process managed to lose the ability to handle file uploads. I've managed to identify that this...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.