在数据库的表里存的是全部路径,如:“C:\Documents and Settings\Administrator\My Documents\My Pictures\1 (11).jpg”
怎么把这个路径变成相对路径啊?

解决方案 »

  1.   

    可以写sql语句update也可以读出来,在用C#修改后插入
      

  2.   

    你存的时候就有问题。应该存1 (11).jpg而不是整个物理路径。/你用String.Split方法进行分割
      

  3.   


    declare @text nvarchar(500)
    set @text='C:\Documents and Settings\Administrator\My Documents\My Pictures\1 (11).jpg'
    select right(@text,charindex('\',reverse(@text))-1)
      

  4.   

    try...
    1. //本地路径转换成URL相对路径
       private string urlconvertor(string imagesurl1)
       {
          string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
          string imagesurl2 = imagesurl1.Replace(tmpRootDir, ""); //转换成相对路径
          imagesurl2 = imagesurl2.Replace(@"\", @"/");
          return imagesurl2;
        }2. //相对路径转换成服务器本地物理路径
       private string urlconvertorlocal(string imagesurl1)
       {
         string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
         string imagesurl2 = tmpRootDir + imagesurl1.Replace(@"/", @"\"); //转换成绝对路径
         return imagesurl2;
        }
      

  5.   

    怎么使用String.Split()呢?
    path.Split("///");对吗?
      

  6.   

    保存时候只保存文件名,如:14.txt
    而不是全部文件路径:C:\14.txt
      

  7.   

    谢谢大家了!
    最后用string.Split()获得了文件名,做出来了