上傳文件后,前臺的訪問問題

来源:互联网 发布:finale mac 破解 编辑:程序博客网 时间:2024/04/29 08:43

protected void Button2_Click(object sender, EventArgs e)
        {
            string strLogoName = "nologo.jpg";
            string strURL = this.TextLink.Text.ToString().Trim();

            if (RadioButtonList1.SelectedIndex==1)
            {
                string strLinkPath = Server.MapPath("../Images/Link");
                strLogoName = "Link" + System.DateTime.Now.Ticks;
                strLogoName += FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("."));
                FileUpload1.SaveAs(strLinkPath + "//" + strLogoName);
            }
            else if (RadioButtonList1.SelectedIndex==0)
            {
                strLogoName = this.txtHTTPLogo.Text.ToString().Trim();
            }

            SqlParameter[] arrParameter = new SqlParameter[3];
            arrParameter[0] = new SqlParameter("@Linkname ", SqlDbType.VarChar, 50);
            arrParameter[0].Value = Convert.ToString(this.TextWord.Text.ToString().Trim());
            arrParameter[1] = new SqlParameter("@wordLink ", SqlDbType.VarChar, 500);
            arrParameter[1].Value = strURL;
            arrParameter[2] = new SqlParameter("@PictureLink ", SqlDbType.VarChar, 200);
            arrParameter[2].Value = strLogoName;
            if (Convert.ToInt32(Sport.SqlHelper.ExecuteNonQuery(Sport.SysConfig.GetConnection(), CommandType.StoredProcedure, "P_InsertLink", arrParameter)) > 0)
            {
                this.Label1.Visible = true;
                this.Label1.Text = "添加鏈接成功!";
            }
            else
            {
                this.Label1.Visible = true;
                this.Label1.Text = "添加鏈接失敗!";
            }
            this.LinkDataBind();
            this.TextLink.Text = String.Empty;
            this.TextWord.Text = String.Empty;
            this.txtHTTPLogo.Text = String.Empty;
        }

 

通過以上程序提交以後 ,數據庫裏面就只有文件名,而沒有完整路徑,要訪問的時候,根據你的程序直接寫就行了

比如數據庫中是a.jpg

那麽路徑就可能是string path="../images/a.jpg";

img.ImgaeUrl=path;