Example of file operations in ASP. NET (VB)

Source: Internet
Author: User
Example of file operations in ASP. NET (VB)

Post: Andy. m Date: popularity: 60

Example of file operations in ASP. NET

1. Write files
Writefile. aspx

<% @ Import namespace = "system. Io" %> 'introduce the required namespace
<%
Response. Write ("writing the content into text file in ASP. NET <br> ")
Dim strwriterobj as streamwriter 'declares a streamwriter object
Strwriterobj = file. createtext ("C:/aspnet.txt") 'creates a text file and assigns it to the streamwriter object.
Strwriterobj. writeline ("Welcome to wonderfull world of ASP. NET programming ")
'Write content to the file
Strwriterobj. Close 'Close the object
Response. Write ("done with the creation of text file and writing content into it ")
%>

2. Read files
Readfile. aspx

<% @ Import namespace = "system. Io" %>
<%
Response. Write ("reading the content from the text file ASPnet. txt <br> ")
Dim streamreaderobj as streamreader 'declares a streamreader object
Dim filecont as string 'declares a variable to save the read content
Streamreaderobj = file. opentext ("C:/aspnet.txt") 'open the file and assign the value to the streamreader object.
Do 'read the file content cyclically by row
Filecont = streamreaderobj. Readline ()
Response. Write (filecont & "<br> ")
Loop until filecont = ""
Streamreaderobj. Close 'close streamreader object
Response. Write ("<br> done with reading the content from the file aspnet.txt ")
%>

3. delete an object
Filedelete. aspx

<% @ Import namespace = "system. Io" %>
<%
File. Delete ("C:/aspnet.txt") 'delete an object
Response. Write ("the file ASPnet is deleted successfully !!! ")
%>

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.