This message was discovered on ASPFriends.com 'aspngcodegiveawayswap' list.
| Robert Chartier |
Comments/feedback welcome
Im going to break down this utility library, into separate posts..one for each section (method + overloads) that I have just so we can have separate threads of conversation for each item.
Robert Chartier Author and Developer 604-975-5590 Click here to reveal e-mail address http://www.aspfree.com/devlinks http://www.aspfree.com/authors/robert http://www.aspalliance.com/nothingmn http://www.15seconds.com/issue/wa.htm#chartier
|
|
| |
| |
| Robert Chartier |
#region GetHttpStream /// <summary> /// GetHttpStream: Converts a URL address to a System.IO.Stream /// </summary> /// <param name="sURL"></param> /// <param name="proxyaddress"></param> /// <param name="proxyport"></param> /// <returns></returns> public System.IO.Stream GetHttpStream(string sURL, string proxyaddress, int proxyport) {
WebRequest wrGETURL; wrGETURL = WebRequest.Create(sURL);
WebProxy myProxy = new WebProxy(proxyaddress,proxyport); myProxy.BypassProxyOnLocal = true;
wrGETURL.Proxy = WebProxy.GetDefaultProxy();
Stream objStream; objStream = wrGETURL.GetResponse().GetResponseStream(); return objStream;
} /// <summary> /// hit any url with GET/POST, with the given parameters (FOR POST), with the username/password /// </summary> /// <param name="sURL"></param> /// <param name="httpmethod"></param> /// <param name="postparams"></param> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public System.IO.Stream GetHttpStream(string sURL, string httpmethod, string postparams, string username, string password) {
byte [] bytes = null; // Get the data that is being posted (or sent) to the server bytes = System.Text.Encoding.ASCII.GetBytes (postparams);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(sURL);
if(username!="") request.Credentials = new NetworkCredential(username,password);
request.Method = httpmethod; request.ContentLength = bytes.Length; Stream sendStream = request.GetRequestStream(); sendStream.Write(bytes,0,bytes.Length); sendStream.Close(); WebResponse response = request.GetResponse(); Stream objStream; objStream = response.GetResponseStream();
return objStream;
} #endregion
Robert Chartier Author and Developer 604-975-5590 Click here to reveal e-mail address http://www.aspfree.com/devlinks http://www.aspfree.com/authors/robert http://www.aspalliance.com/nothingmn http://www.15seconds.com/issue/wa.htm#chartier
|
|
| |
|
| | |
| |
| Robert Chartier |
NOTE: I plan on changing/adding the second method to arrays, and not a stupid string list. :) (It was done in this manner due to project constraints).
#region Simple XML+XSL Transformation /// <summary> /// Transform: Simple Transformation of an XML + XSL /// </summary> /// <param name="xml"></param> /// <param name="xsl"></param> /// <returns></returns> public string Transform(string xml, string xsl) {
System.IO.StringWriter sResult = new System.IO.StringWriter(); System.Xml.XmlDocument docXml = new System.Xml.XmlDocument();
System.Xml.XmlDocument docXsl = new System.Xml.XmlDocument(); System.Xml.Xsl.XslTransform xslTransform = new System.Xml.Xsl.XslTransform();
//LOAD UP THE XML DOCUMENT if (xml.IndexOf("<?xml") >= 0) { //pass xml content in try { docXml.LoadXml(xml); } catch( Exception exc) { }
} else { //try to load via URI try { docXml.Load(xml); } catch( Exception exc) { } }
//LOAD UP THE XSL DOCUMENT //load xsl to a xsltransform object try { xslTransform.Load(xsl); } catch( Exception exc) { }
//try to transform it try { // call transform - output streamed to console xslTransform.Transform(docXml, null, sResult); } catch( Exception exc) { } return sResult.ToString();
} //Transform
/// <summary> /// Transform: transforms and xml+xsl with given xsl parameters /// </summary> /// <param name="xml"></param> /// <param name="xsl"></param> /// <param name="xslParamNames"></param> /// <param name="xslParamValues"></param> /// <returns></returns> public string Transform(string xml, string xsl, string xslParamNames, string xslParamValues) {
System.IO.StringWriter sResult = new System.IO.StringWriter(); XmlDocument docXml = new XmlDocument(); XmlDocument docXsl = new XmlDocument(); //DocumentNavigator navSource; System.Xml.Xsl.XslTransform xslTransform = new System.Xml.Xsl.XslTransform();
//LOAD UP THE XML DOCUMENT if (xml.IndexOf("<?xml") >= 0) { //pass xml content in try { docXml.LoadXml(xml); } catch( Exception exc) { }
} else { //try to load via URI try { docXml.Load(xml); } catch( Exception exc) { } }
//LOAD UP THE XSL DOCUMENT //load xsl to a xsltransform object try { xslTransform.Load(xsl); } catch( Exception exc) { }
//load up the xsl parameters, if any System.Xml.Xsl.XsltArgumentList xslArgs = new System.Xml.Xsl.XsltArgumentList(); if (xslParamNames!=""){ char[] chSplit = {','}; string[] pNames; string[] pValues;
pNames = xslParamNames.Split(chSplit); pValues = xslParamValues.Split(chSplit);
for(int i=0;i<pNames.Length;i++) { xslArgs.AddParam(pNames[i],"",pValues[i]); } }
//try to transform it try { // call transform - output streamed to console if (xslParamNames!=""){ xslTransform.Transform(docXml, xslArgs, sResult); } else { xslTransform.Transform(docXml, null, sResult); } } catch( Exception exc) { } return sResult.ToString();
} //Transform
#endregion
Robert Chartier Author and Developer 604-975-5590 Click here to reveal e-mail address http://www.aspfree.com/devlinks http://www.aspfree.com/authors/robert http://www.aspalliance.com/nothingmn http://www.15seconds.com/issue/wa.htm#chartier
|
|
| |
|
|
|
|
|