Using the FileWebRequest to write to a remote file (C#) : FileWebRequest « Development « ASP.NET Tutorial






<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        Uri uri = new Uri("file://ServerName/Documents/lorum.txt");
        if (uri.Scheme == Uri.UriSchemeFile)
        {
            FileWebRequest request = (FileWebRequest)FileWebRequest.Create(uri);
            FileWebResponse response = (FileWebResponse)request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string tmp = reader.ReadToEnd();
            response.Close();
        }

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>








9.20.FileWebRequest
9.20.1.Using the FileWebRequest to write to a remote file (VB)
9.20.2.Using the FileWebRequest to write to a remote file (C#)