应用于visual studio 2012和sql server作为beckend。 [英] Application in visual studio 2012 and sql server as beckend.

查看:63
本文介绍了应用于visual studio 2012和sql server作为beckend。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查此代码: - 不工作



protected void Button1_Click(object sender,EventArgs e)

{

string path = Server.MapPath(" image");

var filePaths = Directory.GetFiles(path); //这将获取给定文件夹路径中的所有文件

foreach(文件路径中的var filePath)

{

string fileExtension = Path.GetExtension(filePath);

if(b) FileUpload1.HasFile || fileExtension ==" .exe")

{

//你可以在这里做你的东西



Response.Write(无法上传文件);

}

其他

{

FileUpload1.SaveAs(path +//+ FileUpload1.FileName);

Response.Write(上传成功);

}



}

}

Please check this code:- It is not working

protected void Button1_Click(object sender, EventArgs e)
{
string path = Server.MapPath("image");
var filePaths = Directory.GetFiles(path);// this will get all files in given folder path
foreach (var filePath in filePaths)
{
string fileExtension = Path.GetExtension(filePath);
if (FileUpload1.HasFile || fileExtension == ".exe")
{
// you can do ur stuff here

Response.Write("Cannot upload file");
}
else
{
FileUpload1.SaveAs(path + "//" + FileUpload1.FileName);
Response.Write("upload successfully");
}

}
}

推荐答案

它不起作用不是一个好的错误描述 - 有很多很多东西可能不工作就你而言关注,我们不知道您认为代码应该做什么。

然而,有两种可能性让人想起:



1)图像是与当前网页位于同一文件夹中的文件。由于未指定绝对路径,因此将使用相对路径。如果是文件,则GetFiles将失败。

2)您假设此代码在客户端而不是服务器上运行。 C#代码无法访问客户端上的文件或文件夹,只能访问服务器,GetFiles将返回服务器上的文件列表,而不是客户端。所以你的FileUpload1可能还没有把任何文件加载到服务器上......
"It is not working" is not a good error description - there are so many, many things that could be "not working" as far as you are concerned, and we have no idea what you think the code should do.
However, there are two possibilities which spring to mind:

1) "image" is a file in the same folder as the current webpage. Since you do not specify an absolute path, the relative one will be used. If it's a file, GetFiles will fail.
2) You are assuming that this code is working on the client, rather than the server. C# code cannot access files or folders on the client, only the server, and GetFiles will return a list of files on the server, not the client. So the chances are your FileUpload1 has not loaded any files onto the server at all yet...


这篇关于应用于visual studio 2012和sql server作为beckend。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆