如何在asp.net中存在文件时显示警报消息(浏览新文件时) [英] How To Show alert message when file already exists(When Browsing for a new file) in asp.net

查看:89
本文介绍了如何在asp.net中存在文件时显示警报消息(浏览新文件时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
如何在asp.net中获取文件(浏览新文件时)时显示警报消息.

任何建议...

Hello All,
How To Show alert message when file is already taken(When Browsing for a new file) in asp.net..

Any Suggestions...

推荐答案

/*To get user uploaded file name*/
UploadedFile filename = rauPIAMSpeRateLetter.UploadedFiles[0];
strGetFileName = filename.GetName();

                             /*Path to save user uploaded file(Store your path in hidden field)*/
                                string strFileName = hdfUploadPath.Value + strGetFileName;

                                /*Check for existence of file if not exists then I am saving else I am giving message to user*/
                                if (!File.Exists(strFileName))
                                {
                                    filename.SaveAs(strFileName, true);
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Error", "alert('File already exist or rename file then upload');", true);
                                    return;
                                }


文件存在:System.IO.File.Exists.

显示:有很多方法可用;我建议这样做:
File exists: System.IO.File.Exists.

Showing: many methods are available; I would recommend this:
<p><% some_C#_expression_calculating_the_message_text %></p>



请注意,现有文件"只能表示HTTP服务器所在主机的文件系统中的某些文件.因此,您只能计算服务器部分的存在,这使显示"变得容易:无论如何,内容都将在HTTP响应中返回.

—SA



Note that the by existing file you can only mean some file in the file system of the host where the HTTP server works. Consequently, you can only calculate existence on the server part, which makes the "showing" easy: the content is returned in the HTTP response anyway.

—SA


这篇关于如何在asp.net中存在文件时显示警报消息(浏览新文件时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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