summaryrefslogtreecommitdiffstats
path: root/backend/asp-file/Default.aspx.cs
blob: 6bd232ccb9e4d717418dc0b428bec356f24f1b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class backend_asp_file_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();

        string action = Request.Params["action"].ToLower();

        if (action.Equals("list"))
        {
            list();
        }

        if (action.Equals("load"))
        {
            load();
        }

        if (action.Equals("save"))
        {
            save();
        }

        Response.End();
    }

    private void list()
    {
        string[] filePaths = Directory.GetFiles(Server.MapPath("data")); 
        foreach (string filePath in filePaths)
        {
            Response.Write(Path.GetFileName(filePath) + "\n");
        }
    }

    private void load()
    {
        string fNaam = "data/" + Request.Params["keyword"].ToLower();
        Response.ContentType = "text/xml";
        if (File.Exists(Server.MapPath(fNaam)))
        {
            Response.WriteFile(Server.MapPath(fNaam));
        }
        else
        {
            Response.StatusCode = 404;
        }
    }

    private void save()
    {
        string fNaam = "data/" + Request.Params["keyword"].ToLower();
        FileStream fs = new FileStream(Server.MapPath(fNaam), FileMode.Create);

        byte[] buffer = new byte[1024];
        int count;
        while ((count = Request.InputStream.Read(buffer, 0, buffer.Length)) != 0)
            fs.Write(buffer, 0, count);

        fs.Close();
        
    }
}