无法在c#中获取项目中的商店图像路径 [英] unable to get the store image path in the project in c#
问题描述
我正在上传一个文件,我将它存储在项目中,但无法从项目中获取存储路径给出错误
i am uploading a file i am storing it in the project,but unable to get the storing path from the project giving error
if (file1 != null)
{
logofilename = Path.GetFileName(file1.FileName);
logobytes = new byte[file1.ContentLength];
DateTime date = DateTime.Now;
string format = ddMMyyyhhmmsstt
string Jn = (date.ToString(format));
var fileName = string.Concat(logofilename, Jn);
if (file1 != null && file1.ContentLength > 0)
{
// extract only the filename
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath(~/PictureUpload), fileName);
file1.SaveAs(path);
obju.UserProfileImage =file1.SaveAs(path);
}
保存为方法无效
error on save as method void
推荐答案
您将错误的值分配给 UserProfileImage
而不是 -
You are assigning wrong value to UserProfileImage
Instead of-
obju.UserProfileImage =file1.SaveAs(path);
试试这个 -
try this-
obju.UserProfileImage =path; //if UserProfileImage is the string that contains the image path
希望,它有帮助:)
Hope, it helps :)
这条线路没有多大意义
This line doesn't make much sense
obju.UserProfileImage =file1.SaveAs(path);
SaveAs保存文件到给定的路径,它不返回任何东西。问题的解决方案取决于UserProfileImage的类型。如果它需要一个Image,那么你可能需要从你刚刚保存的文件中创建一个新的图像
https://msdn.microsoft.com/en-us/library/system.drawing.image(v = VS .110).aspx [ ^ ]
SaveAs saves the file to the given path, it doesn't return anything. The solution to your problem depends on what type UserProfileImage is. If it expects an Image then you might need to create a new Image from the file you've just saved
https://msdn.microsoft.com/en-us/library/system.drawing.image(v=vs.110).aspx[^]
obju.UserProfileImage = Image.FromFile(path);
您还没有真正发布足够的信息来给出一定的答案。
You haven't really posted enough information to give a certain answer.
这篇关于无法在c#中获取项目中的商店图像路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!