摘要: 最近在的系统用到图片幻灯的效果找了好些,最后保留了两种,因为可以做到图片的自动缩放。 1、Bcastr4.0优秀的图片轮换播放器 2、jQuery 幻灯片阅读全文
posted @ 2011-09-16 01:27 D调de小雨 阅读(96) 评论(0) 编辑
摘要: asp.net mvc jQuery 实现自动刷新阅读全文
posted @ 2011-08-31 22:57 D调de小雨 阅读(299) 评论(4) 编辑

最近项目出使用到了将word文档以二进制的方法存到数据库中,并再次读取出二进制数据转换为word文档。最后总结了一下,不多说看示例方法:

代码
        /// <summary>
        
/// 二进制数据转换为word文件
        
/// </summary>
        
/// <param name="data">二进制数据</param>
        
/// <param name="fileName">word文件名</param>
        
/// <returns>word保存的相对路径</returns>
        public string ByteConvertWord(byte[] data, string fileName)
        {
            
string savePath = @"\SystemWord\"+FormatNowTime(2)+@"\";

            
if (!System.IO.Directory.Exists(GetPath() + savePath))
            {
                Directory.CreateDirectory(GetPath() 
+ savePath);
            }
            savePath 
+= fileName + ".doc";
            
string filePath = GetPath() + savePath;

            FileStream fs;
            
if (System.IO.File.Exists(filePath))
            {
                fs 
= new FileStream(filePath, FileMode.Truncate);
            }
            
else
            {
                fs 
= new FileStream(filePath, FileMode.CreateNew);
            }
            BinaryWriter br 
= new BinaryWriter(fs);
            br.Write(data, 
0, data.Length);
            br.Close();
            fs.Close();
            
return savePath;
        }

        
/// <summary>
        
/// word文件转换二进制数据(用于保存数据库)
        
/// </summary>
        
/// <param name="wordPath">word文件路径</param>
        
/// <returns>二进制</returns>
        private byte[] wordConvertByte(string wordPath)
        {
            
byte[] bytContent = null;
            System.IO.FileStream fs 
= null;
            System.IO.BinaryReader br 
= null;
            
try
            {
                fs 
= new FileStream(wordPath, System.IO.FileMode.Open);
            }
            
catch
            {
            }
            br 
= new BinaryReader((Stream)fs);
            bytContent 
= br.ReadBytes((Int32)fs.Length);

            
return bytContent;
        }

        
/// <summary>
        
/// 项目所在目录
        
/// </summary>
        
/// <returns></returns>
        public string GetPath()
        {
            
return Application.StartupPath;
        }

        
/// <summary>
        
/// 格式化当前时间: 
        
/// 1:yyMMddHHmmss; 2:yyyy-MM\dd\
        
/// </summary>
        
/// <returns></returns>
        public string FormatNowTime(int num)
        {
            
if (num == 1)
            {
                
return DateTime.Now.ToString("yyMMddHHmmss");
            }
            
else if (num == 2)
            {
                
return DateTime.Now.ToString("yyyy-MM"+ @"\" + DateTime.Now.Day;
            }
            
return "";
        }

//测试方法
 private void button1_Click(object sender, EventArgs e)
        {
            
string newWord = ByteConvertWord(wordConvertByte(@"D:\测试文件.doc"), "测试成功");
        }

 

其他方法:来源CSDN:

http://topic.csdn.net/u/20100412/17/fbdeb7a1-412f-4533-93c1-1a2516c3738a.html?seed=38035402&r=64626024#r_64626024


//将文件转换为二进制,并保存到数据库中
           
string strResult = strPath + @"\result.doc";
            System.IO.FileStream fs
= new System.IO.FileStream(@strResult, System.IO.FileMode.Open);
            fs.Position
= 0;
           
byte[] content = new byte[fs.Length];
            fs.Read(content,
0, (int)fs.Length);
            fs.Close();
            fluidDesignDoc.qhse1
= content;//其中qhse1在数据库中保存的类型为OLE对象
            IFluidDesignDocManager manager = new FluidDesignDocManager(); manager.UpdateFluidDesignDoc(fluidDesignDoc); ----

 

//将二进制数据转化为指定位置文件
private void getFile(byte[] content, string filePath)
        {
           
string fileName = filePath;
           
if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
            }
           
//FileStream sw = new FileStream(@fileName, FileMode.Create);
           
//StreamWriter fs = new StreamWriter(sw, Encoding.UTF8);
           
//fs.Write(entity.Content);
            System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
            fs.Write(content,
0, content.Length);
            fs.Flush();
            fs.Close();
            fileName
= System.IO.Path.Combine(Application.StartupPath, fileName);
        }

posted @ 2010-04-13 18:05 D调de小雨 阅读(497) 评论(0) 编辑

    /// <summary>
    /// 字符串截取方法
    /// </summary>
    /// <param name="str">截取字符</param>
    /// <param name="len">大于Len时,截取len</param>
    /// <returns></returns>
    public string Substr(string str, int len)
    {
        if (!string.IsNullOrEmpty(str))
        {
            System.Text.RegularExpressions.Regex rChinese = new Regex(@"[\u4e00-\u9fa5]"); //验证中文
            Regex rEnglish = new Regex(@"^[A-Za-z0-9]+$");  //验证字母

            if (rChinese.IsMatch(str))
            {
                //中文
                return (str.Length > len) ? str.Substring(0, len) + "..." : str; 
            }
            else if (rEnglish.IsMatch(str))
            {
                //英文或数字
                return (str.Length > len * 2) ? str.Substring(0, len * 2) + "..." : str; 
            }

            return (str.Length > len) ? str.Substring(0, len) + "..." : str; 
        }
        return "";
    } 

posted @ 2010-01-19 11:13 D调de小雨 阅读(225) 评论(1) 编辑

1.使用CheckedListBox1.Items.Add循环方式
 
  赋值:
  foreach (DataRow dr in ds.Tables[0].Rows)
  {
     checkedListBox1.Items.Add(dr["Name"]);
  }
 
  选中索引:
  foreach (int indexChecked in checkedListBox1.CheckedIndices)
  {
      MessageBox.Show("Index#: " + indexChecked.ToString());             
  }

  选中值:
  foreach (object itemChecked in chk.CheckedItems)
  {
     MessageBox.Show("Item with title: " + itemChecked.ToString());
  }

2.使用DataSource方式

  赋值:
  CheckedListBox.DataSource = ds.Tables[0];
  CheckedListBox.DisplayMember = "Id";
  CheckedListBox.ValueMember = "Name";

  选中值:
  for (int count = 0; count < CheckedListBox1.CheckedItems.Count; count++)
  {
      string id = (CheckedListBox1.Items[CheckedListBox1.CheckedIndices[count]] as DataRowView)["Id"].ToString(); //获取ID
      string name = (CheckedListBox1.Items[CheckedListBox1.CheckedIndices[count]] as DataRowView)["Name"].ToString(); //获取名称
      MessageBox.Show("Id:" + id + " Name:" + name);
  }

posted @ 2010-01-13 10:10 D调de小雨 阅读(1316) 评论(0) 编辑
摘要: 最近做WinForm遇到个WinForm循环出comboBox且绑定一同数据源时,comboBox一个改变时其他的也同样改变。我使用的一个解决方案:1.ComboBox数据源是list时第一次使用:comboBox1.DataSource = list; 后面的使用:comboBox1.DataSource = list.ToArray(); 2.ComboBox数据源是DataSet时第一次使用...阅读全文
posted @ 2010-01-11 11:31 D调de小雨 阅读(561) 评论(1) 编辑
摘要: 今天在使用IIS6.0发布asp.net网站时,遇到了“您未被授权查看该页”搜集了资料很多,按其配置仍无法解决这问题。最后算是找出了问题所在:1、IIS未注册2、Web 服务扩展(Active Server Pages/Asp.net v1.1.4322(允许) )1、一台新服务器配置基本使用Server2003及IIS6.0发布网站,注意安装后多半并未注册。 注册方法: ...阅读全文
posted @ 2009-12-21 22:16 D调de小雨 阅读(429) 评论(0) 编辑
摘要: 1.可能出现的异常异常信息:试图吊销一个未注册的拖放目标 (异常来自 HRESULT:0x80040100 (DRAGDROP_E_NOTREGISTERED))原因:是Editor本身未被Dispose,其中的Timer还在工作。解决:对加入editor的窗体的FormClosing事件加入:this.editor1.Dispose();2.取值与赋值取值1>. string conten...阅读全文
posted @ 2009-10-15 15:51 D调de小雨 阅读(62) 评论(0) 编辑