北极冰点水 .NET 天空------天空是一个人永远也走不完的大路, 呼吸, 歌唱, 向着阳光

给予我们的誓言 以凝固不化的可能

2008年3月5日 #

如何用C#代码设置文件的附加属性啊 例如author, subject 这些啊

RT
MS太麻烦了,干嘛不直接公布一个方法出来呢
我只找到了读的方法.还要用com控件, Shell32,我把那个类贴在下面,供参考

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;

namespace TestforFile
{
    using Shell32; // Use this namespace after add the reference

    /// <summary>

    /// Returns the detailed Information of a given file.

    /// </summary>

    public class CFileInfo
    {
        private string sFileName = "",
            sFullFileName = "",
            sFileExtension = "",
            sFilePath = "",
            sFileComment = "",
            sFileAuthor = "",
            sFileTitle = "",
            sFileSubject = "",
            sFileCategory = "",
            sFileType = "";

        private long lFileLength = 0,
            lFileVersion = 0;

        private DateTime dCreationDate,
            dModificationDate;

        public CFileInfo(string sFPath)
        {
            // check if the given File exists
            if (File.Exists(sFPath))
            {
                ArrayList aDetailedInfo = new ArrayList();
                FileInfo oFInfo = new FileInfo(sFPath);

                sFileName = oFInfo.Name;
                sFullFileName = oFInfo.FullName;
                sFileExtension = oFInfo.Extension;
                lFileLength = oFInfo.Length;
                sFilePath = oFInfo.Directory.ToString();
                dCreationDate = oFInfo.CreationTime;
                dModificationDate = oFInfo.LastWriteTime;

                #region "read File Details"
                aDetailedInfo = GetDetailedFileInfo(sFPath);
                foreach (DetailedFileInfo oDFI in aDetailedInfo)
                {
                    switch (oDFI.ID)
                    {
                        case 2:
                            sFileType = oDFI.Value;
                            break;

                        case 9:
                            sFileAuthor = oDFI.Value;
                            break;

                        case 10:
                            sFileTitle = oDFI.Value;
                            break;

                        case 11:
                            sFileSubject = oDFI.Value;
                            break;

                        case 12:
                            sFileCategory = oDFI.Value;
                            break;

                        case 14:
                            sFileComment = oDFI.Value;
                            break;

                        default:
                            break;
                    }
                }
                #endregion
            }
            else
            {
                throw new Exception("The given File does not exist");
            }
        }

        #region "Properties"
        public string FileName
        {
            get { return sFileName; }
            set { sFileName = value; }
        }

        public string FilePath
        {
            get { return sFilePath; }
            set { sFilePath = value; }
        }

        public string FullFileName
        {
            get { return sFullFileName; }
            set { sFullFileName = value; }
        }

        public string FileExtension
        {
            get { return sFileExtension; }
            set { sFileExtension = value; }
        }

        public long FileSize
        {
            get { return lFileLength; }
            set { lFileLength = value; }
        }

        public long FileVersion
        {
            get { return lFileVersion; }
            set { lFileVersion = value; }
        }

        public DateTime FileCreationDate
        {
            get { return dCreationDate; }
            set { dCreationDate = value; }
        }

        public DateTime FileModificationDate
        {
            get { return dModificationDate; }
            set { dModificationDate = value; }
        }

        public string FileType
        {
            get { return sFileType; }
        }

        public string FileTitle
        {
            get { return sFileTitle; }
        }

        public string FileSubject
        {
            get { return sFileSubject; }
        }

        public string FileAuthor
        {
            get { return sFileAuthor; }
        }

        public string FileCategory
        {
            get { return sFileCategory; }
        }

        public string FileComment
        {
            get { return sFileComment; }
        }
        #endregion

        #region "Methods"

        private ArrayList GetDetailedFileInfo(string sFile)
        {
            ArrayList aReturn = new ArrayList();
            if (sFile.Length > 0)
            {
                try
                {
                    // Creating a ShellClass Object from the Shell32

                    ShellClass sh = new ShellClass();
                    // Creating a Folder Object from Folder that inculdes the File
                    Folder dir = sh.NameSpace(Path.GetDirectoryName(sFile));
                    // Creating a new FolderItem from Folder that includes the File
                    FolderItem item = dir.ParseName(Path.GetFileName(sFile));
                    // loop throw the Folder Items

                    for (int i = 0; i < 30; i++)
                    {
                        // read the current detail Info from the FolderItem Object

                        //(Retrieves details about an item in a folder. For example, its size, type, or the time of its last modification.)

                        // some examples:
                        // 0 Retrieves the name of the item.
                        // 1 Retrieves the size of the item.
                        // 2 Retrieves the type of the item.
                        // 3 Retrieves the date and time that the item was last modified.
                        // 4 Retrieves the attributes of the item.
                        // -1 Retrieves the info tip information for the item.

                        string det = dir.GetDetailsOf(item, i);

                        // Create a helper Object for holding the current Information
                        // an put it into a ArrayList

                        DetailedFileInfo oFileInfo = new DetailedFileInfo(i, det);
                        aReturn.Add(oFileInfo);
                    }
                }
                catch (Exception)
                {
                }
            }
            return aReturn;
        }
        #endregion
    }

    // Helper Class from holding the detailed File Informations
    // of the System
    public class DetailedFileInfo
    {

        int iID = 0;
        string sValue = "";

        public int ID
        {
            get { return iID; }
            set
            {
                iID = value;
            }
        }

        public string Value
        {
            get { return sValue; }
            set { sValue = value; }
        }

        public DetailedFileInfo(int ID, string Value)
        {
            iID = ID;
            sValue = Value;
        }
    }
}

posted @ 2008-03-05 17:35 北极冰点水 阅读(495) 评论(0) 编辑

2007年4月10日 #

在.NET中使TextBox只能输入数字的方法(key 和 clipboardData)

-- Number TextBox
<asp:TextBox ID="tbNumberInput" runat="server" onkeypress="return isNumberKey(this)" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"></asp:TextBox>
 
function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
 {
   
    return false;
   
 }
 return true;
}

posted @ 2007-04-10 18:04 北极冰点水 阅读(979) 评论(2) 编辑

2006年11月29日 #

怎样在XML中使用&和字符

最近在项目中碰到以前开发人员禁用&字符,但客户现在又要求必须允许输入. 想了想,是啊,没有道理不允许, 开始想到用自定义转义字符,继承xmldocument类来实现不合法的XML字符,但是既然这样,为什么不能用标准的转义字符呢.只是要花点时间fix以前的代码啦.

 下面是五个在XML文档中预定义好的实体:
&lt;             <        小于号 
&gt;            >        大于号
&amp;       &        和 
&apos;       '         单引号 
&quot;        "         双引号 

         实体必须以符号"&"开头,以符号";"结尾。
  如果在XML文档中使用类似"<" 的字符, 那么解析器将会出现错误,因为解析器会认为这是一个新元素的开始。所以不应该像下面那样书写代码:
<message>if salary < 1000 then</message> 
  为了避免出现这种情况,必须将字符"<" 转换成实体,像下面这样: 
<message>if salary &lt; 1000 then</message> 
   注意: 只有"<" 字符和"&"字符对于XML来说是严格禁止使用的。剩下的都是合法的,为了减少出错,使用实体确实是一个好习惯。

posted @ 2006-11-29 09:31 北极冰点水 阅读(788) 评论(0) 编辑

2006年11月21日 #

ViewState深入,Textbox,Checkbox,CheckboxList,RadioButtonList 不能禁止ViewState

ViewState是ASP.NET中用来保存WEB控件回传时状态值一种机制。

 

页面本身将 20 字节左右的信息保存在 ViewState 中,用于在回传时将 PostBack 数据和 ViewState 值分发给正确的控件。因此,即使该页面或应用程序禁用了 ViewState,仍可以在 ViewState 中看到少量的剩余字节。

优先级:
全局配置 < 程序 < 页< 控件

 

注意:下列服务器控件不能禁止ViewState

Textbox 
Checkbox
CheckboxList
RadioButtonList

上面控件的状态通过IPostBackEventHandler 和 IPostBackDataHandler接口处理,而不是ViewState的机制,所以EnableViewState没有效果。
哈哈,刚好解释我上午试验的疑惑.

posted @ 2006-11-21 15:17 北极冰点水 阅读(1063) 评论(3) 编辑

textbox web控件 根本无视enableviewsate 是否true 或者false, 依然能够相应用户的输入

在ASP.Net中WebForm控件有个EnableViewState属性。这个属性究竟有什么用。在VS的hint: Whether the control automatically saves its state for use in round-trips. 原理就是ASP.NET引用了viewstate的机制。在服务器端保存了网页各个控件及页面的状态,这其中包括各个控件在页面上的布局,和他们各自的属性。这些值就保存在ViewState下。我们可以观察Aspx页面的html源代码,假设这个页面上有一个button按钮,和一个listBox控件,html文件如下:

<input type="hidden" name="__VIEWSTATE" value="dDwzODYzNDM5NTU7Oz7FvviJbq45bDa7QJaumIiOhZ8mOQ==" />

 <input type="submit" name="Button1" value="Button" id="Button1" style="height:40px;width:96px;Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 240px" />
 <select name="ListBox1" size="4" id="ListBox1" style="width:152px;Z-INDEX: 102; LEFT: 176px; POSITION: absolute; TOP: 120px"></select>

其值是一长串字符。类型为“hidden”。这个值记录的就是各个控件和页面的状态信息。当用户对页面进行相关操作的时候,状态值发生改变,并将改变的值传递给服务器端。服务器端在比较改变后的状态值和初始值之间的区别,以响应具体的请求。

一旦页面的控件很多,这种频繁的传递控件状态值对网络的消耗是很大的,因此,ASP.Net提供了EnableViewState属性,系统默认的值为true。当设置为true时,在传递状态值时就包括该控件;如果设置为false,则传递状态值时则不包括它。既然状态值不包括该控件,则客户端对它进行的操作,服务器端是不响应的。

我们可以做个实验,在Button1_Click事件中,编写代码:

ListBox.Items.Add(”客户端点击按钮一次!”);

此时运行该应用程序,单击网页上的按钮,在ListBox中会添加内容,不断地单击,内容则不断添加。如果我们将ListBox的EnableViewState属性改为false时,不断单击按钮,则只能添加一次。

这样有什么好处呢?如果我们在开发Web应用程序时,某些控件是不需要接受用户的操作或只需要接受一次操作的时候,我们可以将这些控件的EnableViewState属性改为false,这样可以优化我们的程序,提高网络访问的速度.

按照道理这个原理对于textbox也是同样的,但是在实验过程中发现textbox 根本就无视enableviewsate 是否true 或者false.Textbox2依然能够相应用户的输入. 源码:aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" enableViewState="False"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
  <title>WebForm1</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
  </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <asp:TextBox id="TextBox1" style="Z-INDEX: 100; LEFT: 280px; POSITION: absolute; TOP: 120px"
    runat="server" Text="Build.Com" EnableViewState="False">Build.Com</asp:TextBox>
<asp:TextBox id=TextBox3 style="Z-INDEX: 105; LEFT: 280px; POSITION: absolute; TOP: 200px" runat="server" EnableViewState="False" Text=""></asp:TextBox>
   <asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 168px"
    runat="server" Text="" EnableViewState="False"></asp:TextBox>
   <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 360px; POSITION: absolute; TOP: 240px" runat="server"
    Text="Button" EnableViewState="False"></asp:Button>
   <asp:ListBox id="ListBox1" style="Z-INDEX: 104; LEFT: 144px; POSITION: absolute; TOP: 184px"
    runat="server" EnableViewState="False"></asp:ListBox>
  </form>
 </body>
</HTML>


CS:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
 /// <summary>
 /// Summary description for WebForm1.
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.TextBox TextBox1;
  protected System.Web.UI.WebControls.Button Button1;
  protected System.Web.UI.WebControls.ListBox ListBox1;
  protected System.Web.UI.WebControls.TextBox TextBox2;
  protected System.Web.UI.WebControls.TextBox TextBox3;
 
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // Put user code to initialize the page here
   
  }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   //base.OnInit(e);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {   
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void Button1_Click(object sender, System.EventArgs e)
  {
   ListBox1.Items.Add("客户端点击按钮一次!");
   TextBox3.Text = TextBox2.Text + TextBox1.Text;

  }
 }
}

posted @ 2006-11-21 13:30 北极冰点水 阅读(240) 评论(0) 编辑

2006年5月24日 #

什么是One-Click技术

什么是One-Click技术, 很感兴趣. 朦胧知道用途,却不能明确描述.期待进一步了解
核心应该是:simplicity,就是简单化.
installshield有个click once deployment 应该就是一种应用.
可惜啊今天还碰到了问题, 一个红色错误醒目的出现,找不到原因, 这个是日志
================= Logging started at 5/25/2006 05:32:51 下午 ==================
Preparing the primary application assembly for processing.
Creating the base deployment.
Initializing the default application manifest.
Creating the application manifest folder.
Deleting existing application manifest folder.
Building application files to the release location.
Loading File table
ISDEV : error -6645: C:\WINDOWS\system32\shdocvw.dll failed to load.
 Error: 0
 Error Description:
Adding file 'UploadManager.dll' that is a dependency of component 'STPClient.exe1'
Adding merge module 'Microsoft OLE 2.40 for Windows NT and Windows 95' that is a dependency of component 'STPClient.exe1'
Adding merge module 'Microsoft OLE 2.40 for Windows NT and Windows 95' that is a dependency of component 'Net.SourceForge.Koogra.dll1'
Merging Microsoft OLE 2.40  for Windows NT(TM) and Windows 95(TM) Operating Systems: C:\Program Files\Common Files\Merge Modules\OLEAUT32.MSM
The 'INTERNET' deployment configuration is disabled, skipping.
The 'CDROM' deployment configuration is disabled, skipping.
The 'UNC' deployment configuration is disabled, skipping.
The ClickOnce build process has finished with:  1 Errors and 0 Warnings.
================= Logging stopped at 5/25/2006 05:33:18 下午 ==================
Log file has been created: <file:D:\MiantainProject\STP\Setup\NTUCInstallProject\Build Report\5-25-2006 05-32-51 下午.txt>

fileslist里压根就没加这个dll,也没有任何file depend 他.真是郁闷...............

posted @ 2006-05-24 11:23 北极冰点水 阅读(541) 评论(0) 编辑

2006年4月18日 #

未将对象引用到对象的实例

摘要: I meet other puzzlement similar as your. 我们在一个项目中封装了一个errorprovider控件,在另外一个项目中引用,在开发人员的其中两台机子上一点问题都没有,在我的机子上就有未将对象引用到对象的实例, 换了本本来试也一样. 但是如果重新拖入这个控件,就什么都没有问题也没有. 但是vss上签入的控件属性就丢了,唉,协同开发遭遇麻烦.但是如果不修改,只是编...阅读全文

posted @ 2006-04-18 10:23 北极冰点水 阅读(301) 评论(1) 编辑

2006年4月17日 #

asp.net执行.sql文件 和 Cmd 模式执行sql文件

摘要: asp.net执行.sql文件 今天想通过执行.sql脚本达到恢复统一客户端数据库版本数据的目的,找了段代码.好像有用//应用Process前请引用:System.Diagnostics命名空间. string infile=System.Web.HttpContext.Current.Server.MapPath("test.sql"); Process sqlprocess=new Proce...阅读全文

posted @ 2006-04-17 11:53 北极冰点水 阅读(1041) 评论(0) 编辑

2006年2月20日 #

后期维护成本

摘要: 好久没有来了,最近被一个维护项目忙晕了头,历经几拨develpor得一个项目进入了我得管辖范围,而作为leader, 历史悠久得项目bug层出不穷,代码混乱,而uat时间又如此紧迫, ........................阅读全文

posted @ 2006-02-20 09:06 北极冰点水 阅读(88) 评论(0) 编辑

2006年1月13日 #

用.net开发不同操作系统下应用的winform的size大小问题

摘要: 2006年来了,2005走了,新的一年本该辞旧迎新,可我耍了一圈vs2005又耍回去了,又开始耍vs2003了.而且还又耍回了windows程序.用,net开发windows程序到时第一招,其实不应算是开发,应该算是维护吧,因为人家的project已经成型,已经开始uat了.而我,也只是观察员的身份.不过还是有点收获吧,记下来供怀恋和旁人借鉴.我的中文xp系统,原开发人员是e2000系统,项目一签...阅读全文

posted @ 2006-01-13 16:13 北极冰点水 阅读(396) 评论(1) 编辑