常见实用的C#语句汇总(不断整理中)
来源:互联网 发布:php vcruntime140.dll 编辑:程序博客网 时间:2024/04/30 20:18
1、键值的使用(多用在批量取代情况)
//需引用using System.Collections; public void WriteHTML(string str) { Hashtable Content = new Hashtable(); Content.Add("&author", "作者"); Content.Add("$title", "标题"); foreach (DictionaryEntry de in Content) //循环遍历 { str = str.Replace(de.Key.ToString(), de.Value.ToString()); } }
2、判断是从哪个链接(或搜索引擎)地址进来的
protected void Page_Load(object sender, EventArgs e) { HttpRequest hr = System.Web.HttpContext.Current.Request; if (hr.UrlReferrer != null) { string domain = hr.UrlReferrer.Host; Response.Write("链接过来的服务器名:" + hr.UrlReferrer.Host); Response.Write("<br />"); Response.Write("链接过来的链接地址:" + hr.UrlReferrer.ToString()); //Request.Browser; Request.Url; Request.UrlReferrer; Request.ServerVariables["SERVER_NAME"].ToString(); } }
3、程序控制手机号发送
/// <summary> /// 需引用using System.Net; /// </summary> /// <returns>返回状态:0成功;-1该用户或密码错误;-2余额不足;-3失败:没有正确格式号码;-4非法关键字;-5发送内容不能为空;-6未开通API权限;-7账 号被锁定;-88短信类型错误</returns> public static string SendMobileCode(string mobile, string content) { string url = "http://112.125.54.58/api/http_api.php?mark=send&username=11&password=22&mobile=" + mobile.Trim() + "&content=" + content.Trim() + "&sendtime=&fstd=5"; WebRequest wRequest = WebRequest.Create(url); WebResponse wResponse = wRequest.GetResponse(); Stream stream = wResponse.GetResponseStream(); StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default); string r = reader.ReadToEnd(); reader.Close(); stream.Close(); wResponse.Close(); return r; }
4、数据流操作
protected void Page_Load(object sender, EventArgs e) { string templatePath = ""; //Server.MapPath("~/") + "\\temp\\createhtml.config"或http://www.abc.com/createhtml.aspx string path = ""; WebRequest HttpWebRequest = WebRequest.Create(templatePath); //适用远程http打头的 WebResponse HttpWebResponse = HttpWebRequest.GetResponse(); StreamReader sr = new StreamReader(HttpWebResponse.GetResponseStream(), System.Text.Encoding.UTF8); //StreamReader sr = File.OpenText(templatePath); //适用本地文件 string strHtml = sr.ReadToEnd(); //此步执行后可对strHtml进行复杂字符串处理 //path要写入的完整文件路径。System.Text.Encoding.GetEncoding("gb2312")或"utf-8" //append确定是否将数据追加到文件。如果该文件存在,并且append为false,则该文件被改写。 //如果该文件存在,并且append为true,则数据被追加到该文件中。否则,将创建新文件。 StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.UTF8); sw.WriteLine(strHtml); sw.Flush(); sw.Close(); sr.Close(); }
- 常见实用的C#语句汇总(不断整理中)
- 常见实用的SQL语句、存储过程、游标、函数、视图(不断整理中)
- VS2008使用过程中问题汇总(不断整理中...)
- 常见端口号(整理会不断的增加的)
- 常用T_sql语句收集(不断整理中)
- [整理]有用的SQL语句(不断增加)
- jdk中实用的类(不断补充.........)
- 我喜欢的文章链接(不断整理中... ...)
- Windows的一些常用管理命令(不断整理中)
- 一些技术的总结整理(不断追加中)
- CSDN问题汇总(不断总结中)
- ajax 学习资料(不断整理中)
- FAQ整理(不断添加中)
- FAQ整理(不断添加中)
- 学习笔记(不断整理更新中)
- ACM术语(不断整理中)
- C# 的常见误区整理
- 【C#2.0】点滴(不断补充中......)
- JavaScript File API 文件上传
- java字节流对汉字输出为乱码的问题
- Tips-C#
- 用 Eclipse 平台进行 C/C++ 开发
- 基于linux 守护进程的分析与实现
- 常见实用的C#语句汇总(不断整理中)
- Magento网店自定义模板初探(2)——开启Debug模式
- Handler+Looper+MessageQueue深入详解案例
- JDK网络API
- Hadoop的安装配置
- WPF中的文件浏览对话框
- 数据库管理脚本(一个session只能执行一次?)
- SqlServer2000登陆角色的具体权限
- Firefox无法启动,提示Profile is yet in use by another Firefox