public void InsertArticleImage(int a_id) { for (int i = 0; i < rpImage.Items.Count; i++) { ArticleImageInfo info = new ArticleImageInfo(); Image lbtxtFormatName = (Image)rpImage.Items[i].FindControl("Image1"); if (lbtxtFormatName != null) { if (System.IO.File.Exists(Server.MapPath(Tools.GetAppSettings("ProductImageTempPath") + lbtxtFormatName.AlternateText))) { System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(Tools.GetAppSettings("ProductImageTempPath") + lbtxtFormatName.AlternateText)); file.CopyTo(Server.MapPath(Tools.GetAppSettings("ArticleTruePath") + lbtxtFormatName.AlternateText)); } info.a_id = a_id; info.ap_imagename = lbtxtFormatName.AlternateText; info.ap_name = lbtxtFormatName.AlternateText; } aiBLL.Insert(info); } }
protected void btImage_Click(object sender, EventArgs e) { if (fuImage.HasFile) { string imgFilename = WebUtility.ChangeFileNameAsRandom(fuImage.FileName); if (WebUtility.CheckImageExt(System.IO.Path.GetExtension(imgFilename))) { string serverFileName = WebUtility.MergePathAndFileName(imgFilename, Tools.GetAppSettings("ArticleTruePath")); fuImage.SaveAs(serverFileName); ArticleImageInfo info = new ArticleImageInfo(); info.a_id = Tools.GetInt32SafeFromQueryString(this.Page, "id", 0); info.ap_name = imgFilename; info.ap_imagename = imgFilename; aiBLL.Insert(info); tfBLL.InsertTempFiles("Ariticle", Tools.GetAppSettings("ArticleTruePath") + imgFilename); rpImage.DataSource = aiBLL.GetDataByAid(Tools.GetInt32SafeFromQueryString(this.Page, "id", 0)); rpImage.DataBind(); } } else { this.ShowMessage("請選擇一個檔案"); } }