Click here to Skip to main content
15,923,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am uploading a file i am storing it in the project,but unable to get the storing path from the project giving error

C#
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
Posted
Updated 14-Dec-15 22:09pm
v2

You are assigning wrong value to UserProfileImage
Instead of-
C#
obju.UserProfileImage =file1.SaveAs(path);

try this-
C#
obju.UserProfileImage =path; //if UserProfileImage is the string that contains the image path


Hope, it helps :)
 
Share this answer
 
v2
This line doesn't make much sense

C#
obju.UserProfileImage =file1.SaveAs(path);


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[^]

C#
obju.UserProfileImage = Image.FromFile(path);


You haven't really posted enough information to give a certain answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900