小总结

1.IMAGE.SAVE(@path) 

string path=System.Web.Hosting.HostingEnvironment.MapPath(“~/Images”)

函数得到的路径 如果用在IMAGE.SAVE(@path) 函数中 需要转义符号

或者path = path.Replace("\", "//"); 在使用保存路径

16进制颜色代码转Color类型:ColorTranslator.FromHtml(color);
Color类型转16进制颜色代码:ColorTranslator.ToHtml(_color);

---------------------------------------------------------------------------------------------------

2. 图片保存到流 MemoryStream 需要注意的地方

Stream ms = new MemoryStream()

imgSrc.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

imgSrc.Dispose();

ms.Position = 0;
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, 0, buffer.Length);
ms.Dispose();

写字符串到文件操作

string path = System.Web.Hosting.HostingEnvironment.MapPath("~");
path += pi.PAGE_NAME + ".html";
if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); }

StreamWriter sr = System.IO.File.CreateText(path);
sr.Write(pi.PAGE_CONTENT);
sr.Close();
sr.Dispose();

---------------------------------------------------------------------------------------------------

3. 用P3P header解决iframe跨域访问cookie/session

当利用IFRAME时,记得要在相应的动态页的页头添加一下P3P的信息,否则IE会自觉的把IFRAME框里的COOKIE给阻止掉.

只需要设置 P3P HTTP Header,在隐含 iframe 里面跨域设置 cookie 就可以成功。他们所用的内容是:

P3P: CP='CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR'

通过在代码上加Response.AddHeader("P3P", "CP=CAO PSA OUR")

---------------------------------------------------------------------------------------------------

4.Linq to entity  indexof ()方法想当于  sql 中的like 语句,'%010%'

 用StartWith ()  方法可以实现  sql 中 like '010%'的效果,它是从开头字母做比对。

5.CSS 自适应 大小 文字 图片

.mc{25%; 25%!important; position:absolute; z-index:999; margin-top:-52%; margin-left:-40%;}
.mc-name{
font-size: 16px;
display: block;
font-weight: 400;
position:absolute;
float:left;
margin-left:55%;
margin-top:-40%;
font-family:"微软雅黑";
z-index:9999;}
@@media only screen and (max- 1300px) { .mc-name{ font-size: 36px; margin-left:70%;margin-top:-43%!important; }}
@@media only screen and (max- 800px) { .mc-name{ font-size: 25px; margin-left:64%;margin-top:-41%!important; }}
@@media only screen and (max- 350px) { .mc-name{ font-size: 16px; margin-top:-40%; }}
@@media only screen and (max- 300px) { .mc-name{ font-size: 14px;margin-top:-40%; }}
@@media only screen and (max- 250px) { .mc-name{ font-size: 12px;margin-top:-40%;margin-left:50%; }}

 6.LINQ TO ENTITY 修改实体状态 

var osm = _db.ObjectStateManager;

 osm.ChangeObjectState(entityModel, System.Data.EntityState.Detached);

Added——实体标记为added。 
Deleted——实体标记为deleted。 
Modified——实体已经被修改。 
Unchanged——实体还没有被修改。 
Detached——实体不能被追踪  释放实体

查询数据库 表数量

 SELECT * FROM sysobjects WHERE (xtype = 'U')

C = CHECK 约束
D = 默认值或 DEFAULT 约束
F = FOREIGN KEY 约束
L = 日志
FN = 标量函数
IF = 内嵌表函数
P = 存储过程
PK = PRIMARY KEY 约束(类型是 K)
RF = 复制筛选存储过程
S = 系统表
TF = 表函数
TR = 触发器
U = 用户表
UQ = UNIQUE 约束(类型是 K)
V = 视图
X = 扩展存储过程

File to base64String  传输

//FileInfo fi = new FileInfo("d://1312274613032.dat");

FileStream fs = new FileStream(Server.MapPath("~/1312274613032.dat"), System.IO.FileMode.Open, System.IO.FileAccess.Read);

FileStream fs = new FileStream("d://1312274613032.dat", System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] filecontent = new byte[fs.Length];
fs.Read(filecontent, 0, filecontent.Length);
fs.Close();
fs.Dispose();
string ECGFile = Convert.ToBase64String(filecontent);

byte[] filecontent2 = Convert.FromBase64String(EcgFile);

File.WriteAllBytes(Server.MapPath("~/"+bb+".doc"), filecontent2);

7. VS2013 关闭预览功能

工具-》选项-》环境-》选项卡和窗口 去掉倒数第三个选项的勾选。

8. MVC4 设置html 页面为起始页  在 Global.asax 中增加 下面函数

protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.FilePath == "/") Context.RewritePath("productGS.html");
}

原文地址:https://www.cnblogs.com/90nice/p/3736237.html