本文介绍了如何重命名图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我将从适当的文件夹中检索文件.我可以得到图像名称.但我不能重命名该图像文件.请帮助我

Hi Friends,
I will retrieve the file from a appropriate folder. i can able to get the image name . but i can''t rename that image file . Please Help me

namespace webshoppe
{
    public partial class Image : System.Web.UI.Page
    {
        private static DirectoryInfo dir;
        private static FileInfo[] images;
        private static int currIndex = 0;
        private static int count = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
         dir = new DirectoryInfo(@"D:\Image");

           images = dir.GetFiles("*.jpg");


            count = images.Length;
            if (!IsPostBack)
            {
                if (count > 0)
                {
                    string strImageurl = images[currIndex].Name;
                    strImageurl = "~/Image/" + strImageurl;
                    Image1.ImageUrl = strImageurl;

                    currentname();
                }
            }
        }


        public void currentname()
        {

            string strImageurl = images[currIndex].Name;
            lblimage.Text = strImageurl;
             images[currIndex].Name= txt_imagename.Text;

        }
        protected void submitbtn_Click(object sender, EventArgs e)
        {
            if (count > 0)
            {
                if (currIndex == (count - 1))
                {
                    currIndex = 0;
                }
                else
                {
                    currIndex++;
                }
                string newUrl = images[currIndex].Name;
                newUrl = "~/Image/" + newUrl;
                Image1.ImageUrl = newUrl;
                currentname();
            }
        }
    }
}



错误:



Error:

'System.IO.FileSystemInfo.Name' cannot be assigned to -- it is read only

推荐答案


System.IO.File.Move(oldname, newname);



这篇关于如何重命名图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:34
查看更多