C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Please Please help.................. tooo urgent


Posted Date: 10 Jul 2006      Posted By: Devi      Member Level: Silver     Points: 2   Responses: 10



Hi,

I want to select a directory and upload all the files in that to the server using asp.net..... is there anyway to do that...... if anyone knows please tell me the code... its too urgent... i have to submit it on this week.......Pleaseeeeeeee





Responses

Author: Subodh kumar Prajapati    06 Jun 2007Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi Devi,
You can use the Html control or Asp control to browse the file from spacific directory.
add a input button from the toolbox of Html control. and set the type is "File" of that control.
now you'll see that a browser button will be displayed. now you can select the files through this browser button.
To save the file, you can use this code:
bttBrowse.SaveAs("c:/tt.txt");

where bttBrowse is the name of control which is added.

I think this will be help to you. If want to more information then you can tell or ask to me.

ok byeee...
From : subodh kumar
9891428085



Author: Arunagiri Gunasekaran    13 Oct 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 5

Dear Devi,
If you want to fetch all the files from the specific directory, then you cannot use the file upload control. You have to give the folder path manually,

After that you can use the System.IO namespace and get all the files in the given directory and move to the server.

other wise, View this link given below. I hope, it will help you to move further.

http://aspalliance.com/150_how_to_upload_files_in_asp_net

All the Best :)



Author: Prajho    11 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 0

Use Follow Code:

The Controls are Treeview,Gridview

using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

private void FillDirectory(TreeNode parent, string strPath)
{
DirectoryInfo dr = new DirectoryInfo(strPath);
if (dr.Exists)
{
foreach (DirectoryInfo d in dr.GetDirectories())
{
TreeNode node = new TreeNode();
node.Text = d.Name;
node.Value = d.FullName;
node.PopulateOnDemand = true;
node.SelectAction = TreeNodeSelectAction.SelectExpand;
parent.ChildNodes.Add(node);
}
}
}

protected void DirTreeview_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
string selectedstring = e.Node.Value;
string strFileName = Path.Combine(currentFolderPath, selectedstring);
FillDirectory(e.Node, strFileName);
//BindDirContents(e.Node, gridviewFiles);
}

public String currentFolderPath
{
get
{
if (ViewState["m_currentFolderPath"] != null)
return ViewState["m_currentFolderPath"].ToString().Trim();
else
return string.Empty;
}
set
{
ViewState["m_currentFolderPath"] = value;
}
}

private static void BindDirContents(TreeNode node, System.Web.UI.WebControls.GridView gridview)
{
// bind the gridview to the datasource
gridview.DataSource = new System.IO.DirectoryInfo(node.Value).GetFiles();
gridview.DataBind();
}

protected void gridviewFiles_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.IO.FileSystemInfo item = (System.IO.FileSystemInfo)e.Row.DataItem;
ImageButton imageButton = (ImageButton)e.Row.FindControl("btnItemIcon");

System.IO.FileInfo fileInfo = (System.IO.FileInfo)item;

Label lblSize = (Label)e.Row.FindControl("lblSize");
lblSize.Text = string.Format("{0:N0} KB", fileInfo.Length / 1000);

if ((fileInfo.Name.EndsWith(".rtf") || fileInfo.Name.EndsWith(".doc") || fileInfo.Name.EndsWith(".txt")))
{
imageButton.ImageUrl = @"Image/doc.jpg";
}
else
{
imageButton.ImageUrl = @"Image/voice.png";
}
}
}

protected void DirTreeview_SelectedNodeChanged(object sender, EventArgs e)
{
BindDirContents(this.DirTreeview.SelectedNode, this.gridviewFiles);
}

protected void gridviewFiles_RowCommand(object sender, GridViewCommandEventArgs e)
{
// handle either opening the item or rebinding the grid
if (e.CommandName == "ItemClick")
{
string name = (string)e.CommandArgument;
System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(this.DirTreeview.SelectedNode.Value);

if (System.IO.File.Exists(System.IO.Path.Combine(dinfo.FullName, name)))
{
System.IO.FileInfo fileInfo = new System.IO.FileInfo(System.IO.Path.Combine(dinfo.FullName, name));
// they clicked on a file, download it to there PC
this.Response.Clear();
this.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
this.Response.WriteFile(fileInfo.FullName);
this.Response.End();
}
else
{
foreach (TreeNode node in this.DirTreeview.SelectedNode.ChildNodes)
{
if (node.Text == name)
{
node.Selected = true;
node.Expanded = true;

// expand the parents
TreeNode parentNode = node.Parent;
while (parentNode != null)
{
parentNode.Expanded = true;
parentNode = parentNode.Parent;
}

// bind the gridview to the datasource
BindDirContents(node, this.gridviewFiles);
break;
}
}
}
}
}
}



Default.aspx.txt
Author: Mohan Gajula    08 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 1

Insert a fileupload control

insert a button control

now in the button click write

Fileupload.saveas("myfile.ext");



Author: Rams    08 Dec 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

Hi,

Refer to this link for a detailed Multiple file upload with ASP.Net
But the code is in vb.net, if you want the code in c# then just use any code converters.

here is the link
http://www.codetoad.com/asp.net_multiplefileupload.asp



Author: Rams    08 Dec 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 2

Hi Devi,

You can refer to this link even, this is a step by step guidance for uploading files

http://support.microsoft.com/kb/323245

All the best
-Rams



Author: siri    12 Dec 2008Member Level: BronzeRating: 2 out of 52 out of 5     Points: 1

hi DEVI,
You can refer to this link even, this is a step by step guidance for uploading files

http://support.microsoft.com/kb/323245



Author: vipul patni    29 Dec 2008Member Level: BronzeRating: 2 out of 52 out of 5     Points: 1

U can use this link!!

http://aspalliance.com/150_how_to_upload_files_in_asp_net

Regards
Vipul



Author: Varma Suresh    27 Jan 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 0

hi,
U can directly upload using upload control,

H2H
Defeat the Defeat before the Defeat Defeats you
With Regards
V.Suresh Varma



Author: LOGESHWARAN    11 Feb 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 4

How to control the size of file uploaded to the web server?

While uploading a file to the web server, we have a limit of 4MB by default. We can either decrease or increase this value. The value is set in the key, maxRequestLength of machine config file.

There is a maxRequestLength limit in the machine.config file (look for the <system.web> section), in the httpRuntime settings that you need to alter/raise if you want to accept anything larger than 4Mb. These are the standard settings for the httpRuntime:

U can use this link!!

http://aspalliance.com/150_how_to_upload_files_in_asp_net


<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>

REGARDS
LOGESHWARAN.P
mailto: logesh_ajax@logeshwaran.co.cc



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : no of click on advertisement in asp.net application
Previous : Please tell me .Net interview Questions for 2+ Years Exp
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use