2006年08月26日

经过测试,如果文件夹有太多文件,你用程序访问的时候,速度也会变慢,因为本质上树结构放到内存中,太多的叶子会导致内存使用加大以及访问变慢,通常是2k为单元这样。

同时处理大量图片,这样的话,用生成图像的方法生成速度太慢,此方法不用打开图像获取图像象素

引用Microsoft Shell Controls and Automation(com)

using System.IO;
using Shell32;

string strFilePath = @"E:\\Test\\Test.jpg";
ShellClass _ShellClass = new ShellClass();
Folder dir = _ShellClass.NameSpace(Path.GetDirectoryName(strFilePath));
FolderItem _FolderItem = dir.ParseName(Path.GetFileName(strFilePath));
string det = dir.GetDetailsOf(_FolderItem,0);

说明:
0 :文件名
1 : 大小
2 :类型
3 :修改时间
4 :创建时间
5 :访问时间
26:分辨率
27:水平像素
27:垂直像素

注意:

不是所有的文件都有extension信息,但是只要你在操作系统查看文件属性能看到的,就能通过此方法获得。26、27、28属性跟操作系统有关

2006年08月25日

public static void Thumbnail(string originalImagePath, string thumbnailPath, int thumbnailWidth, int thumbnailHeight, string mode)
{
 System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);

 int X = 0;
 int Y = 0;

 int originalWidth = originalImage.Width;
 int originalHeight = originalImage.Height;

 switch(mode)
 {
  case "WH"://指定高宽缩放(可能变形)
   thumbnailWidth = thumbnailWidth;
   thumbnailHeight = thumbnailHeight;
   break;
  case "W"://指定宽,高按比例
   thumbnailHeight = Convert.ToInt32(originalHeight * ((double)thumbnailWidth/originalWidth));
   break;
  case "Cut"://指定高宽裁减(不变形)
   if(Convert.ToDouble(originalWidth)/Convert.ToDouble(originalHeight) > Convert.ToDouble(thumbnailWidth)/Convert.ToDouble(thumbnailHeight))
   {
    originalWidth = Convert.ToInt32(originalHeight * ((double)thumbnailWidth/thumbnailHeight));
    X = (originalImage.Width – originalWidth)/2;
   }
   else
   {
    originalHeight = Convert.ToInt32(originalWidth * ((double)thumbnailHeight/thumbnailWidth));
    Y = (originalImage.Height – originalHeight)/2;
   }
   break;
 }
 //新建一个bmp图片
 System.Drawing.Image Image_bmp = new System.Drawing.Bitmap(thumbnailWidth, thumbnailHeight);
 //新建一个画板
 System.Drawing.Graphics Graphics_bmp = System.Drawing.Graphics.FromImage(Image_bmp);
 //设置高质量插值法
 Graphics_bmp.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
 //设置高质量,低速度呈现平滑程度
 Graphics_bmp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 //清空画布并以透明背景色填充
 Graphics_bmp.Clear(System.Drawing.Color.Transparent);
 //在指定位置并且按指定大小绘制原图片的指定部分
 Graphics_bmp.DrawImage(originalImage,new System.Drawing.Rectangle(0,0,thumbnailWidth,thumbnailHeight),new System.Drawing.Rectangle(X,Y,originalWidth,originalHeight),System.Drawing.GraphicsUnit.Pixel);
 try
 {
  //以jpg格式保存缩略图
  Image_bmp.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
 }
 catch(Exception ex)
 {
  throw ex;
 }
 finally
 {
  originalImage.Dispose();
  Image_bmp.Dispose();
  Graphics_bmp.Dispose();
 }
}

目前获取图像象素方法如下:
System.Drawing.Image _Image = new System.Drawing.Bitmap(FileName);
FileName_Pixel_Width = _Image.Width;
FileName_Pixel_Height = _Image.Height;

获取文件其他属性方法如下:
System.IO.FileInfo _FileInfo = new System.IO.FileInfo(FileName);
string FileInfo_Size = _FileInfo.Length/1024;
string FileInfo_Date = _FileInfo.LastWriteTime.ToString();
string FileInfo_Name = _FileInfo.Name;

UploadFile.PostedFile.ContentLength/1024

ddlPhotoColl.Items.Clear();
while (dbReader.Read())
{
 ddlPhotoColl.Items.Add(new ListItem(dbReader["PhotoColl"].ToString(),dbReader["PhotoID"].ToString()));
}

private int GetRecordCount()
{
string strSql = "select count(*) as tt";
strSql += "from photocoll";
strSql += "where mobile=" + smobile;           

SqlConnection dbConn = DbConnection.GetSqlConn();
SqlCommand dbCmd = new SqlCommand(strSql, dbConn);
SqlDataReader dbReader = dbCmd.ExecuteReader();

int nCount = 0;
if(dbReader.Read())
nCount = Convert.ToInt32(dbReader["tt"]);
           
dbReader.Close();
dbConn.Close();
return nCount;
}

2006年08月24日

btnSubmit.Attributes.Add("onclick","javascript:window.showModelessDialog(‘Webform2.aspx’,'base target=_self’,'center:yes’);");

@ 弹出的对话框居中显示。

public static void showMessage(System.Web.UI.Page _Page, string Message)
{
 Message = Message.Replace("/n","");
 string strScript = "<script language=’javascript’>";
 strScript += "alert(‘"+Message+"’)";
 strScript += "</script>";
 if(!_Page.IsStartupScriptRegistered("ShowMsg"))
 {
  _Page.RegisterStartupScript("ShowMsg",strScript);
 }
}

public static string AlertScript(string Message)
{
 return String.Format("<script language = javascript>alert(‘{0}’);</script>", Message);
}

2006年08月22日

窗口的形式打开

父窗口:
window.open(Url);

子窗口:
opener.document.all.CardID.value = strX;

对话框的形式打开

父窗口:
getValue(objX)
{
 strX = showModalDialog(Url);
 objX.value = strX;
}

子窗口:
window.returnValue = strY;

@ 同一个站点不同的虚拟目录可以操作,不同的站点不可以传值操作。