获取使用 ajax AsyncFileUpload 保存的文件的新文件名?
我正在使用ajax工具包中的asyncfileupload ajax插件保存一个文件,当我保存它时,我正在更改文件名(以避免多个文件同名)。
文件上传后,用户需要知道文件的名称,因此我在 onclientuploadcomplete 事件中使用此 javascript 代码。
function UploadComplete(sender, args) {
alert(args.get_fileName());
}
这是有效的,除非它获取的是旧名称,而不是新名称(由服务器端确定)。有什么办法让它返回新名称而不是旧名称?或者有什么办法可以实现这一目标?
这是我在获取新文件名后面的代码中的代码:
string filename = DateTime.Now.ToString("dMyHmsf") + e.filename;
string strPath = MapPath("~/SavedImages/") + filename;
AsyncFileUpload1.SaveAs(strPath);
I'm saving a file with the asyncfileupload ajax plugin from the ajax toolkit and when I save it I'm changing the filename (to avoid multiple files with the same name).
After the file is uploaded, the user needs to know what the file has been named so I'm using this javascript code on the onclientuploadcomplete event.
function UploadComplete(sender, args) {
alert(args.get_fileName());
}
This works except it gets the old name, not the new name (which is determined server-side). Is there any way to get it to return the new name rather than the old name? Or any work around to achieve this?
This is my code in the code behind the get the new filename:
string filename = DateTime.Now.ToString("dMyHmsf") + e.filename;
string strPath = MapPath("~/SavedImages/") + filename;
AsyncFileUpload1.SaveAs(strPath);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从 http://forums.asp.net/post/4139037.aspx 它对我有用...
从那里复制代码:
背后的代码:
I got the answer from http://forums.asp.net/post/4139037.aspx It works for me...
copied code from there:
the code behind:
将文件名写入代码隐藏中的隐藏字段并在客户端代码中读取该值怎么样?
How about writing the filename to a hiddenfield in the codebehind and the reading that value in your clientside code?