posts - 4,  comments - 0,  trackbacks - 0
  2009年10月2日

Many web developers came to the problem that they are not able to change value of file input field from Java Script in the web application. There is no access to value field of file input tag because of security restriction. However there is a trick how to erase this field if you need it in your application.


You can simply redraw the html block where your input tag is located. In this case all data will remain the same except the selected file value.

<script language=”javascript” src=”jquery-1.3.2.min.js” type=”text/javascript”>
</script>

<script language=”javascript”>
function example_reset_html(id) {
$(’#'+id).html($(’#'+id).html());
}
</script>
<form>
<div style=”float: left;” id=”example_file”><input type=”file” /></div>
<input type=”button” value=”Clear” onclick=”example_reset_html(’example_file’);”  />
</form>

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

<div id="uploadFile_div"> <input type="file" class="fieldMoz" id="uploadFile" onkeydown="return false;" size="40" name="uploadFile"/> </div> <a onclick="clearFileInputField('uploadFile_div')" href="javascript:noAction();">Clear</a>

<script> function clearFileInputField(tagId) { document.getElementById(tagId).innerHTML = document.getElementById(tagId).innerHTML; } </script>

posted @ 2009-10-02 13:25 chenshichang 阅读(65) | 评论(0) |  编辑
  2009年6月10日
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string temp="";

   //取得选择的资料

        for (int i = 0; i <= GridView1.Rows.Count - 1;i++ )
            {
                CheckBox chkb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
                if (chkb.Checked)
                {
                    temp += chkb.Text + ",";
                }
            }
        if (temp != "")
        {
            temp = temp.Substring(0, temp.Length - 1);
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-disposition", "attachment; filename=tokens.pdf");

            string[] temp1 = temp.Split(',');

    //产生临时套版,存在时先删掉

            if (File.Exists(Request.MapPath("~/temp.pdf")))
            {
                File.Delete(Request.MapPath("~/temp.pdf"));
            }
            string MasterPdfFile = Request.MapPath("~/temp.pdf");
            PdfCopyFields mypdfcopy = new PdfCopyFields(new FileStream(MasterPdfFile, FileMode.CreateNew));
            int i = 0;
            foreach (string temp2 in temp1)
            {
                SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["cns_mcl"].ConnectionString);
                SqlCommand sqlcmd = new SqlCommand("", conn);
                conn.Open();
                sqlcmd.CommandText = "select post_no,pos_title,pos_text from post where post_no=@post_no";
                sqlcmd.Parameters.AddWithValue("@post_no", temp2);

                SqlDataReader reader = sqlcmd.ExecuteReader();

      //套用使用的样版pdf

                PdfReader pdfReader = new PdfReader(Request.MapPath("~/fund_bill.pdf"));
                string tmpfilepath = Request.MapPath("~/temp/temp" + i.ToString() + ".pdf");
                FileStream tmppgoutputfile = new FileStream(tmpfilepath, FileMode.CreateNew);
                PdfStamper pdfStamper = new PdfStamper(pdfReader, tmppgoutputfile);
                //PdfStamper pdfStamper = new PdfStamper(pdfReader, Response.OutputStream);
                //PdfStamper pdfStamper = new PdfStamper(pdfReader, ms);
                pdfStamper.Writer.CloseStream = false;
                pdfStamper.FormFlattening = false;
                AcroFields pdfForm = pdfStamper.AcroFields;
                BaseFont.AddToResourceSearch("iTextAsian.dll");
                string fontPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"".."Fonts"kaiu.ttf";

                BaseFont bfChinese = BaseFont.CreateFont(
                    fontPath,
                    BaseFont.IDENTITY_H,
                    BaseFont.NOT_EMBEDDED
                );
                //BaseFont bfChinese = BaseFont.CreateFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.EMBEDDED);
                //            string fontPath = Environment.GetFolderPath(Environment.SpecialFolder.System) +
                //@"".."Fonts"comic.TTF";
                //            BaseFont bfChinese = BaseFont.CreateFont(
                //                 fontPath,
                //                 BaseFont.IDENTITY_H, //横式中文
                //                 BaseFont.NOT_EMBEDDED
                //             );
                //BaseFont bfChinese = BaseFont.CreateFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.EMBEDDED);
                Font fontChinese = new Font(bfChinese, 16f, Font.NORMAL);
                if (reader.Read())
                {
                    pdfForm.SetFieldProperty("comp_name_1", "textfont", bfChinese, null);
                    pdfForm.SetField("comp_name_1", reader["post_no"].ToString());
                    pdfForm.SetFieldProperty("comp_name_2", "textfont", bfChinese, null);
                    pdfForm.SetField("comp_name_2", reader["pos_title"].ToString());
                    pdfForm.SetFieldProperty("comp_name_3", "textfont", bfChinese, null);
                    pdfForm.SetField("comp_name_3", reader["pos_text"].ToString());
                }
                reader.Dispose();
                conn.Close();
                pdfStamper.Close();
                tmppgoutputfile.Close();
                PdfReader nwpgreader = new PdfReader(tmpfilepath);
                PdfTemplate page = pdfStamper.GetImportedPage(nwpgreader, 1);
                mypdfcopy.AddDocument(nwpgreader);
                i++;
            }
            mypdfcopy.Close();
            PdfReader respreader = new PdfReader(MasterPdfFile);
            PdfStamper respOutStamper = new PdfStamper(respreader, Response.OutputStream);
            respOutStamper.Close();
            if (Directory.Exists(Request.MapPath("~/temp")))
            {
                Directory.Delete(Request.MapPath("~/temp"), true);
                Directory.CreateDirectory(Request.MapPath("~/temp"));
            }

        }
    }
}
posted @ 2009-06-10 13:47 chenshichang 阅读(117) | 评论(0) |  编辑
  2009年3月14日

 

当我们对查询后的dataset以回圈进行资料集的处理时,如果使用remove,移除某一列资料,资料集的索引将会改变

for(int i=0;i<ds.table[0].rows.count;i++)

{

 if(i==2)

ds.table[0].rows.removeAt(i) ;

i++ //因为索引已改变

}


posted @ 2009-03-14 13:26 chenshichang 阅读(27) | 评论(0) |  编辑
  2009年3月11日

 

今天,好不容易,博客申请通过了,值得纪念

这是我的第一个海外的博客

接下来就要好好想想我要在这里记录什么或留下什么了....

博客的第一篇就先这样记录


posted @ 2009-03-11 16:12 chenshichang 阅读(3) | 评论(0) |  编辑