Use ASP and asp.net to create folders and files.

Source: Internet
Author: User
Tags create directory flush
Asp.net| Create

Asp:

<%
Sub WriteFile (file)
Response.Write "File:" +file
Dim FSO, TF
Set fso = CreateObject ("Scripting.FileSystemObject")
Set tf = fso. CreateTextFile (file, True)
Tf. WriteLine ("Testing 1, 2, 3.")
Tf. WriteBlankLines (3)
' Write a line.
Tf. Write ("This is a test.")
Tf. Close
Set tf = Nothing
Set fso = Nothing
End Sub

Sub CreateFolder (PATH)
Dim Fso,fldr
Set fso = CreateObject ("Scripting.FileSystemObject")
Set Fldr = fso. CreateFolder (PATH)
Response.Write "Create directory:" &fldr. Name
Set Fldr = Nothing
Set fso = Nothing
End Sub

Path = Request.QueryString ("path")
filename = request.querystring ("filename")
File = path + "\" + filename
If path<> "" or filename<> "" Then
CreateFolder (PATH)
WriteFile (file)
End If
%>

asp.net

<%@ Page language= "C #" debug= "true" contenttype= "text/html" responseencoding= "gb2312"%>
<%@ Import namespace= "System.Diagnostics"%>
<%@ Import namespace= "System.IO"%>

<%
String filestr=request.params["file"]+ "";
Filestr=filestr. Trim ();
if (filestr== "") {
Response.Write ("File is null<p>");
Return
}

Response.Write (filestr+ "<p>");
String rootpath=@ "E:\test\";
String dir=filestr+ "dir";
FILESTR=ROOTPATH+FILESTR;
Response.Flush ();

if (directory.exists (Rootpath+dir)) Response.Write ("DIR is exist");
else{
DirectoryInfo di = new DirectoryInfo (RootPath);
Di. Createsubdirectory (dir);
Response.Write ("Create dir:" +directory.createdirectory (dir));
}

Response.Write ("Start Write file str<p>");
Response.Flush ();

using (StreamWriter sw = new StreamWriter (FILESTR))
{
String line= "Test Ming";
Sw. Write (line);
Sw. Close ();
}
%>

Summary: ASP and asp.net can create folders and files, ASP is using FSO components, and asp.net is a class library, so when the ASP does not support FSO, the above code can not work, and asp.net will not have this problem. However, the asp.net operation requires sufficient permissions, and the ASP appears to have this vulnerability.




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.