Загрузка файлов с помощью Server.MapPath () и FileUpload. SaveAs ()

У меня есть административный раздел веб-сайта, над которым я сейчас работаю, который имеет 4 элемента управления FileUpload для определенных целей. Мне нужно знать, что когда я использую метод Server.MapPath () в методах SaveAs () элемента управления FileUpload, будет ли он по-прежнему использоваться на веб-сервере после того, как я загрузил веб-сайт? Насколько мне известно, SaveAs () требует абсолютного пути, поэтому я сопоставляю путь с Server.MapPath ()

if (fuLogo.HasFile) //My FileUpload Control : Checking if a file has been allocated to the control
        {
            int counter = 0;  //This counter Is used to ensure that no files are overwritten.
            string[] fileBreak = fuLogo.FileName.Split(new char[] { '.' });
            logo = Server.MapPath("../Images/Logos/" + fileBreak[0] + counter.ToString()+ "." + fileBreak[1]);  // This is the part Im wondering about. Will this still function the way it should on the webserver after upload?
            if (fileBreak[1].ToUpper() == "GIF" || fileBreak[1].ToUpper() == "PNG")
            {
                while (System.IO.File.Exists(logo))
                {
                    counter++; //Here the counter is put into action
                    logo = Server.MapPath("../Images/Logos/" + fileBreak[0] + counter.ToString() + "." + fileBreak[1]);
                }
            }
            else
            {
                cvValidation.ErrorMessage = "This site does not support any other image format than .Png or .Gif . Please save your image in one of these file formats then try again.";
                cvValidation.IsValid = false;
            }
            if (fuLogo.PostedFile.ContentLength > 409600 )  //File must be 400kb or smaller
            {
                cvValidation.ErrorMessage = "Please use a picture with a size less than 400 kb";
                cvValidation.IsValid = false;

            }
            else
            {

                if (fuLogo.HasFile && cvValidation.IsValid)
                {
                    fuLogo.SaveAs(logo); //Save the logo if file exists and Validation didn't fail. The path for the logo was created by the Server.MapPath() method.
                }

            }
        }
        else
        {
            logo = "N/A";
        }
7
задан Eon 28 April 2011 в 09:47
поделиться