<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出 通用对话框 选择好路径后 确定 ,编辑框里就会显示选择的路径
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)