最近遇到要在windows桌面程式中用程式去開啟加密過的PDF文件,並且要在程式中讓使用者輸入PDF開啟密碼後直接開啟檔案,即檔案開啟不再要求輸入密碼,由於Adobe好像無法以command的方式帶入密碼開啟檔案,也查無相關API,最後只好另外找了元件iTextSharp來代替。
在將iTextSharp加入專案後,可以用PdfReader讀入加密過的PDF檔案,並進行PDF文件的操作
最近遇到要在windows桌面程式中用程式去開啟加密過的PDF文件,並且要在程式中讓使用者輸入PDF開啟密碼後直接開啟檔案,即檔案開啟不再要求輸入密碼,由於Adobe好像無法以command的方式帶入密碼開啟檔案,也查無相關API,最後只好另外找了元件iTextSharp來代替。
在將iTextSharp加入專案後,可以用PdfReader讀入加密過的PDF檔案,並進行PDF文件的操作
所以應該要在GridView.RowCreated 事件中隱藏欄位,Create事件是在DataBound後發生的,所以此時資料已經繫結到GridView,就不會發生PostBack取不到值的狀況
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { e.Row.Cells[RowIndex].Visible = false; }
查詢
// 查詢 var result = from q in mydt.AsEnumerable() select q; // 防止NULL值 if (result.FirstOrDefault<DataRow>() != null) { DataTable dt = result.CopyToDataTable<DataRow>(); foreach (DataRow dr in dt.Rows) { Response.Write( string.Format("{0} - {1} - {2} - {3}", dr["Id"].ToString(), dr["Name"].ToString(), dr["Age"].ToString(), dr["Sex"].ToString())); } }
WHERE
// 有條件查詢 var result = from q in mydt.AsEnumerable() where q.Field<int>("Age") > 30 select new UserInfo() { Id = q.Field<int>("Id"), Name = q.Field<string>("Name"), Age = q.Field<int>("Age"), Sex = q.Field<int>("Sex") }; foreach (UserInfo info in result) { Response.Write(string.Format("{0} - {1} - {2} - {3}", info.Id, info.Name, info.Age, info.Sex)); }
COUNT