js上传文件小问题

nitaiyoucala 2010-09-23 02:08:15
js上传文件时 路径是C:\Date\a.jpg

怎么把a.jpg保存到项目的文件夹中? 有没有c#中的SaveAs
...全文
173 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiangaylian 2010-09-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wwfgu00ing 的回复:]
C# code

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1……
[/Quote]
答非所问!!
cloudgamer 2010-09-24
  • 打赏
  • 举报
回复
js本身不能上传文件的啊
君望永远 2010-09-24
  • 打赏
  • 举报
回复
保存文件是服务端语言的操作 客户端JS顶多做些Check
wwfgu00ing 2010-09-24
  • 打赏
  • 举报
回复

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>FileUpload.SaveAs Method Example</title>
<script runat="server">

protected void UploadButton_Click(object sender, EventArgs e)
{
// Before attempting to save the file, verify
// that the FileUpload control contains a file.
if (FileUpload1.HasFile)
// Call a helper method routine to save the file.
SaveFile(FileUpload1.PostedFile);
else
// Notify the user that a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload.";
}

void SaveFile(HttpPostedFile file)
{
// Specify the path to save the uploaded file to.
string savePath = "c:\\temp\\uploads\\";

// Get the name of the file to upload.
string fileName = FileUpload1.FileName;

// Create the path and file name to check for duplicates.
string pathToCheck = savePath + fileName;

// Create a temporary file name to use for checking duplicates.
string tempfileName = "";

// Check to see if a file already exists with the
// same name as the file to upload.
if (System.IO.File.Exists(pathToCheck))
{
int counter = 2;
while (System.IO.File.Exists(pathToCheck))
{
// if a file with this name already exists,
// prefix the filename with a number.
tempfileName = counter.ToString() + fileName;
pathToCheck = savePath + tempfileName;
counter ++;
}

fileName = tempfileName;

// Notify the user that the file name was changed.
UploadStatusLabel.Text = "A file with the same name already exists." +
"<br />Your file was saved as " + fileName;
}
else
{
// Notify the user that the file was saved successfully.
UploadStatusLabel.Text = "Your file was uploaded successfully.";
}

// Append the name of the file to upload to the path.
savePath += fileName;

// Call the SaveAs method to save the uploaded
// file to the specified directory.
FileUpload1.SaveAs(savePath);

}

</script>

</head>
<body>

<h3>FileUpload.SaveAs Method Example</h3>

<form id="Form1" runat="server">

<h4>Select a file to upload:</h4>

<asp:FileUpload id="FileUpload1"
runat="server">
</asp:FileUpload>

<br /><br />

<asp:Button id="UploadButton"
Text="Upload file"
OnClick="UploadButton_Click"
runat="server">
</asp:Button>

<hr />

<asp:Label id="UploadStatusLabel"
runat="server">
</asp:Label>

</form>

</body>
</html>

纯唇Yu弄 2010-09-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wuyq11 的回复:]

fileupload中选择文件,上传saveas到WEB中路径
[/Quote]
++
daifangci 2010-09-24
  • 打赏
  • 举报
回复
js是不能把图片保持到服务器的,必须用类和后台代码。
wuyq11 2010-09-23
  • 打赏
  • 举报
回复
fileupload中选择文件,上传saveas到WEB中路径
  • 打赏
  • 举报
回复
建议先系统看下资料,没有相关的基础认识,是没法讨论的。
MSDNXGH 2010-09-23
  • 打赏
  • 举报
回复
有啊
SaveAs有啊,用fileupdata上传控件,就有一个asveas方法

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧