我正在开发一个项目。现在我想将上传的图像保存到 -
中的文件夹中(http://myipaddress//DinegenieApi//category).
此文件夹位于C - inetpub - > DinegenieApi - >类别中。 我收到错误URI格式不受支持。但是当我在浏览器中输入此URL时,我能够访问此文件夹。
实际上我正在检查类别文件夹是否已存在,然后直接保存图像,如果不存在,则首先创建一个名为category的文件夹,然后将图像保存到该文件夹。 以下是我正在使用的文件上传代码:
protected Tuple<string, string, string> fileupload(FileUpload fileupload, string foldername)
{
Tuple<string, string, string> imgdetails;
string pathreturn = "";
string fileextension = (Path.GetExtension(fileupload.FileName)).ToLower();
string name = "-" + fileupload.PostedFile.FileName;
string filename = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss").Replace(":", "-") + name;
if (fileextension == ".jpeg" || fileextension == ".jpg" || fileextension == ".gif" || fileextension == ".png")
{
if (fileupload.PostedFile.ContentLength < 512000)
{
//string a = Server.MapPath("~/Filestore/") + foldername;
//string ipaddress=getipaddress();
string ipaddress = "http://172.16.0.18:8080";
string a = ipaddress + "//DinegenieApi//" + foldername;
Uri test = new Uri(a);
DirectoryInfo mydir = new DirectoryInfo(a);
if (Directory.Exists(mydir.ToString()))
{
fileupload.SaveAs(a + "\\" + filename);
}
else
{
Directory.CreateDirectory(a);
fileupload.SaveAs(a + filename);
}
pathreturn =a;
lblmsg.Text = "";
imgdetails = new Tuple<string, string, string>(pathreturn, filename, lblmsg.Text);
}
else
{
lblmsg.Text = "File size should be less than 500kb";
lblmsg.Visible = true;
imgdetails = new Tuple<string, string, string>("", "", lblmsg.Text);
}
}
else
{
lblmsg.Text = "File type should be jpeg,png,gif";
lblmsg.Visible = true;
imgdetails = new Tuple<string, string, string>("", "", lblmsg.Text);
}
return imgdetails;
}