图像显示在本地计算机上,但不显示在Web服务器上 [英] Image is displaying in local machine but not displaying on the web server

查看:59
本文介绍了图像显示在本地计算机上,但不显示在Web服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要如何在服务器的文件夹中上传文件.
以及如何定义其路径.

请检查.下一行适用于localhost,但不适用于Web
SaveLocation = Server.MapPath(〜/Kamna Group网站/" + fn);
可以吗?
该路径是否与访问Image1.ImageUrl
中的图像有关
我正在给我涂胶

I want how to upload file in a folder of server.
and how to define its path.

Please check.Below line is working for localhost but not working for web
SaveLocation=Server.MapPath("~/Kamna Group Website/"+fn);
Is it ok ?
Is this path is relevent to access image in Image1.ImageUrl

i am giving my coading

void page_Load(Object sender, EventArgs e)
    {
    con = new OleDbConnection();
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/kamnagroup.mdb") + "";
    con.Open();
    ds = new DataSet();
    string sql = "select photo,agent,point,aname,branch from joining WHERE point=(SELECT MAX(point) FROM joining)";
    da = new OleDbDataAdapter(sql, con);
    da.Fill(ds, "joining");
    DataRow dRow = ds.Tables["joining"].Rows[0];
    System.Web.UI.WebControls.Label lbl2 = new System.Web.UI.WebControls.Label();
    lbl2.Text = dRow.ItemArray.GetValue(0).ToString();
    lb1.Text = dRow.ItemArray.GetValue(1).ToString();
    lb2.Text = dRow.ItemArray.GetValue(2).ToString();
    lb3.Text = dRow.ItemArray.GetValue(3).ToString();
    lb4.Text = dRow.ItemArray.GetValue(4).ToString();
    fn = System.IO.Path.GetFileName(lbl2.Text.Trim()); Image1.ImageUrl = fn;
    con.Close();
    }
void sub(Object s, EventArgs e)
    {
    con.Open();
    Int32 x = 0; string y = GetRandomString(x);
    int y1 = 0;
    string y2 = "Code";
    string s1 = t1.Text.Trim();
    string m;
    int r = 0;
    DataRow[] rs;
    rs = ds.Tables["joining"].Select("aname='" + s1 + "'");
    r = rs.Length;
    if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
        {
        fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
        //Image1.ImageUrl=fn;
        fn = y + fn;
        //Response.Write(fn);
        //Response.Write("<br>");
        SaveLocation = Server.MapPath("~/Kamna Group Website/" + fn);
        photo = SaveLocation;
        com = con.CreateCommand();
        com.CommandText = "Insert into joining(aname,fathname,dob,pob,add1,mob,city,state,pcode,panno,nominee,relation,photo,bank,branch,account,acctype,intby,codno,doi,agent,point,refno) values('" + t1.Text.Trim() + "','" + t2.Text.Trim() + "','" + t3.Text.Trim() + "','" + t4.Text.Trim() + "','" + texta1.Value + "','" + t7.Text.Trim() + "','" + t5.Text.Trim() + "','" + t6.Text.Trim() + "','" + t8.Text.Trim() + "','" + t11.Text.Trim() + "','" + t9.Text.Trim() + "','" + t10.Text.Trim() + "','" + photo + "','" + t12.Text.Trim() + "','" + t13.Text.Trim() + "','" + t14.Text.Trim() + "','" + d1.SelectedItem.Text + "','" + t15.Text.Trim() + "','" + t16.Text.Trim() + "','" + t17.Text.Trim() + "','" + y2 + "','" + y1.ToString() + "','" + y + "')";
        try
            {
            File1.PostedFile.SaveAs(SaveLocation);
            com.ExecuteNonQuery();
            System.Web.UI.WebControls.Label lbl1 = new System.Web.UI.WebControls.Label();
            lbl1.ForeColor = System.Drawing.Color.Blue;
            lbl1.BackColor = System.Drawing.Color.Yellow;
            lbl1.Text = "You have joined us.We will contect you soon!";
            ph1.Controls.Add(lbl1);
            }
        catch (Exception ex)
            {
            Response.Write(ex.Message);
            }
        }
    else
        {
        Response.Write("Please a file to upload");
        }
    con.Close();
    }
private string GetRandomString(int seed)
    {
    const string alphabet = "abcdefghijklmnopqrstuvwxyz";
    Random rnd = new Random((seed + DateTime.Now.Millisecond));
    string result = rnd.Next(1000000, 9999999).ToString();
    string alphaChar = alphabet.Substring(rnd.Next(0, alphabet.Length - 1), 1);
    int replacementIndex = rnd.Next(0, (result.Length - 1));
    result = result.Remove(replacementIndex, 1).Insert(replacementIndex, alphaChar);
    return result;
    }



[edit]已添加代码块,将我的内容作为纯文本..."选项已禁用-OriginalGriff [/edit]



[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]

推荐答案



我不能说我理解您的问题是什么,但是我只能看到您的路径有问题.
代字号(〜)代表ASP.NET中应用程序的根目录.
如果您想使用代码路径(在代码后),建议您使用
Hi,

I can''t say that I understood what your problem is, but all I can see is that you have problems with paths.
The tilde (~) character represents the root directory of the application in ASP.NET.
If you want to use paths through code (in code-behind) I suggest you to use
Request.ApplicationPath

,然后将相对文件夹结构附加到该路径..
您可以在此处上找到有关ASP.NET路径的好文章. a> [ ^ ].

and then append relative folder structure to it..
You have good article about ASP.NET paths here[^].


这篇关于图像显示在本地计算机上,但不显示在Web服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆