Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created September 30, 2015 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/f021cd0bd3c817e7f6d0 to your computer and use it in GitHub Desktop.
Save bjoerntx/f021cd0bd3c817e7f6d0 to your computer and use it in GitHub Desktop.
protected void Button1_Click(object sender, EventArgs e)
{
// save the document to a string variable
var RTFDocument = String.Empty;
TextControl1.SaveText(out RTFDocument,
TXTextControl.Web.StringStreamType.RichTextFormat);
// create a new WebRequest
WebRequest request = WebRequest.Create(
"http://" + Request.Url.Authority + "/Home/SaveTemplate");
// set the POST data
var postData = "documentName=" + TextBox1.Text;
postData += "&document=" + RTFDocument;
// encode the data as an byte[] array
var data = Encoding.ASCII.GetBytes(postData);
// set the method, content type and length
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
// write the data to the request stream
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
// get response from HttpPost method
WebResponse response = (HttpWebResponse)request.GetResponse();
// read the data and check for return value "True"
var dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string sReturnValue = reader.ReadToEnd();
if (sReturnValue == "True")
lblInfo.Visible = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment