Asp. NET checks whether a file exists

Source: Internet
Author: User
Tags website server

This tutorial shows how we can verify that the file exists or does not receive the execution code representations about the file. The version in C #.


It can be very useful to perform certain lines of code before checking for a file. It prevents error messages from attempting to manipulate files that do not exist, for example. Using System.IO, we can see if there is a file available in a directory that is convenient.

Using System.IO;

Server intelligence assists, businesses of all sizes and their hosting needs, provide fully configured server solutions plus Active Server Management services. Server Intelligence specializes in providing complete Internet server solutions and stands ready to support their expert twenty four-three hundred and sixty fifths active support team.

The ASPX page looks like this:

<form id= "Form1" runat= "Server" >
Search for a file (inc. extension to = if it exists in the media directory.<br/>
Hint:try delete.gif<br/>
<br/>
<asp:textbox id= "TextBox1" runat= "Server" ></asp:textbox><br/>
<asp:button id= "Button1" runat= "server" text= "Go"/><br/>
<asp:label id= "Label1" runat= "Server" ></asp:Label>
</form>

We migrated to the website server intelligence one weekend and the installation was so smooth that we were starting and running out. They help us with everything we need to do with all the apps. With the help of the server intelligence, we can avoid any trouble www.111cn.net/!

Logical check to see if there is any text when the button is pressed first. If there is text currently, it will check to see if this text file is a folder on the media. The user will be notified if there is a file or not.
Code-behind looks like this:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.IO;

public partial class _default:system.web.ui.page
{

protected void Page_Load (object sender, EventArgs e)
{
if (IsPostBack)
Doesfileexist (TextBox1.Text);
}

public void Doesfileexist (string searchstring)
{
if (TextBox1.Text!= "")
{
String Imagefolder;
Imagefolder = Server.MapPath ("/media/") + searchstring.tostring ();
if (file.exists (Imagefolder))
{
Label1.Text = "File <b>" + searchstring + "</b> <u>does</u> exist in '/media/' folder."
}
Else
{
Label1.Text = "File <b>" + searchstring + "</b> <u>does not</u> exist in '/media/' folder."
}
}
Else
Label1.Text = "Please enter some Text."
}

}

Reprint Please specify: www.111cn.net/net/net.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.