asp.net选择文件夹的控件

asp.net选择文件夹的控件,第1张

你 好 什么叫做没有打开文件夹的控件?我是这么做的 现在程序里面建个文件夹,也不可以不用建前台代码:<th>上传文件:</th>

<td class="style1">

<asp:TextBox runat="server" ID ="dataurl" Width="50%" Visible="false"></asp:TextBox>

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

<asp:Button ID="Button3" runat="server" Text="上传" OnClick="UpLoad" Height="25" Width="25%"/>

<asp:Label ID ="lab2" runat="server" Text="上传成功!" ForeColor="Red" Visible="false"></asp:Label>

</td>后台代码: /// <summary>

/// 保存文件

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

///

protected void UpLoad(object sender, EventArgs e)

{

foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)

{

string Path = Server.MapPath(@"../../Uploads") //如果路径不存在,则创建

if (System.IO.Directory.Exists(Path) == false)

{

System.IO.Directory.CreateDirectory(Path)

}//file.GetName()取得文件名

string filename = file.GetName().ToString() //取得文件名(包括路径)里最后一个"."的索引

int index = filename.LastIndexOf(".")

//取得文件扩展名

string extendName = filename.Substring(index) //取得原文件名不包含后缀名

string fileNameFirst = filename.Substring(0, index) //用当前时间为文件重名名,确保文件名不重复

string datename = DateTime.Now.ToString("yyyyMMddHHmmss") string newFileName = fileNameFirst + datename + extendName

//组合路径

Path = Path + "/" + newFileName //保存

file.SaveAs(Path, true) this.dataurl.Visible = true

this.lab2.Visible = true

this.FileUpload1.Visible = false

this.Button3.Visible = false

this.dataurl.ReadOnly=true

this.dataurl.Text = newFileName //Response.Write("f1:" + fileNameFirst)

//Response.Write("f2:" + Path)

}

}

选择文件夹  在工具箱 - 对话框 里选择 FolderBrowserDialog 添加 到设计器中

然后 代码写在  按钮事件里

FolderBrowserDialog1.ShowDialog()

textbox1.text =FolderBrowserDialog1.SelectedPath

选择文件 在工具箱 - 对话框 里选择 OpenFileDialog

把 OpenFileDialog1.ShowDialog()

TextBox1.Text = OpenFileDialog1.FileName

写到按钮事件下

如图

点击按钮会d出 通用对话框  选择好路径后 确定 ,编辑框里就会显示选择的路径


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11998933.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存