-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: ThreeGVBangels
Message 1 in Discussion
Hi,
I have Component one Webgrid,I am getting the Directories in the grid form
server,mappath.
Same directories i want to get into drowdownlist but it is not binding the
data properly it is repeating.
pls go thro the code give me solution
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using C1.Web.C1WebGrid ;
using System.IO;
namespace PrismRaptor.Common
{
/// <summary>
/// Summary description for UploadFile.
/// </summary>
public class UploadFile : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected C1.Web.C1WebGrid.C1WebGrid C1WebGrid1;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.HtmlControls.HtmlInputFile File2;
protected System.Web.UI.WebControls.DropDownList cboFolders;
protected System.Web.UI.HtmlControls.HtmlInputButton CmdUpload;
protected System.Web.UI.WebControls.Label Label1;
// private void SetEventHandlers()
// {
// this.cmdUploads.ServerClick += new
System.EventHandler(this.cmdUpload_ServerClick);
// }
private void Page_Load(object sender, System.EventArgs e)
{
// this.SetEventHandlers();
//uploadFiles = "";
string[] Folder =
System.IO.Directory.GetDirectories(Server.MapPath(".."));
string [] FileName ;
DataTable dt = new DataTable();
dt.Columns.Add("Folder");
dt.Columns.Add ("File");
for(int i = 0; i < Folder.Length; i++)
{
FileName = System.IO.Directory.GetFiles
(Folder[i].ToString());
for(int j = 0; j < FileName.Length; j++)
{
DataRow dr = dt.NewRow();
dr["Folder"] =
System.IO.Path.GetFileName(Folder[i]);
dr["File"] =
System.IO.Path.GetFileName(FileName[j]);
dt.Rows.Add(dr);
cboFolders.DataSource = dt;
cboFolders.DataTextField = ("Folder");
cboFolders.DataBind();
}
}
C1WebGrid1.DataSource = dt;
C1WebGrid1.DataBind();
}
// public void UploadFiles(object Sender,EventArgs E)
// {
//
// if (File2.PostedFile !=null) //Checking for valid file
// {
// // PostedFile.FileName gives the entire path.Use
Substring function to
rip of the filename.
// string strFileName =
File2.PostedFile.FileName.Substring(File2.PostedFile.FileName.LastIndexOf("\\")
+ 1) ;
// string strFileType = File2.PostedFile.ContentType ;
// int intFileSize =File2.PostedFile.ContentLength;
//
// //Checking for the file length
// if (intFileSize <=0)
// Response.Write(" <font color='Red'>Uploading
of file " + strFileName
+ " failed </font>");
// else
// {
// File2.PostedFile.SaveAs(Server.MapPath(".\\" +
strFileName));
// Response.Write( "<font color='green'>Your file
" + strFileName + " of
type " + strFileType + " and size " + intFileSize.ToString() + " was
uploaded successfully</font>");
// }
// }
// }
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.LinkButton2.Click += new
System.EventHandler(this.LinkButton2_Click);
this.CmdUpload.ServerClick += new
System.EventHandler(this.CmdUpload_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LinkButton2_Click(object sender, System.EventArgs e)
{
string path = "C:\\InetPub\\wwwroot\\PrismRaptor\\" ;
if(Directory.Exists(path))
{
Response.Write("This Directory already existes");
return;
}
else
{
DirectoryInfo dirInfo =
Directory.CreateDirectory(path);
}
}
private void CmdUpload_ServerClick(object sender, System.EventArgs e)
{
HttpPostedFile folders = File2.PostedFile ;
string fname = Path.GetFileName(folders.FileName);
string curDir = this.Server.MapPath("..");
string fDir = curDir + Path.DirectorySeparatorChar + "Upload"
+
Path.DirectorySeparatorChar ;
if (folders.ContentLength < 1)
{
Response.Write("File does not exists");
return;
}
if (!File.Exists(fDir))
{
Directory.CreateDirectory(fDir);
}
folders.SaveAs(fDir + fname );
Response.Write( "Uploaded Successfully");
}
}
}
_________________________________________________________________
Earn without investing. http://go.msnserver.com/IN/48713.asp Sell anything
on www.baazee.com.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]