Uploaded files are excluded from the folder
-
HumaMunir wrote:
excluded from my ASP.Net project
What?! What are you talking about?! Are you seriously mean that some uploaded file will became part of your PROJECT?! Do the files stored on disk? That's all you have done with your code... Anyway to what project and for what purpose do you want to add uploaded files to your project?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
The idea is that the admin will upload the newsletter, that will be shown to every user. This is not something exceptional, I have done this before using file upload. You can upload the files by giving a path and then can store the same path in the database to show them later. But this time all the uploaded files are invisible,in other words, are not included in my asp.net project's folder.
Regards HumaMunir
-
Hello Everyone, I am uploading an image file using asp file upload control. This is my code to upload the file in the folder.
public string UploadPicture()
{
if(fuImage.HasFile )
try
{fuImage.SaveAs(Server.MapPath("~/assets/ImgNewsletter/") + fuImage.FileName ); string imagePath = "~/assets/ImgNewsletter/" + fuImage.FileName; return imagePath; } catch (Exception ex) { return ""; } return ""; }
and I have added this in my web.config
My problem is that even after the files are uploaded, they are excluded from my ASP.Net project. Kindly let me know whats wrong with my code? Many Thanks,
Regards HumaMunir
HumaMunir wrote:
catch (Exception ex) { return ""; }
That's a very bad, really terrible, coding practice. Don't do so. An exception occured. You just swallowed it. Perhaps the user had no priviledges to write to that folder. Also note: how will you later be able to access those files? Do you have some database table or some other mechanism to find out which files exist and to generate the html links to them?
-
The idea is that the admin will upload the newsletter, that will be shown to every user. This is not something exceptional, I have done this before using file upload. You can upload the files by giving a path and then can store the same path in the database to show them later. But this time all the uploaded files are invisible,in other words, are not included in my asp.net project's folder.
Regards HumaMunir
HumaMunir wrote:
his time all the uploaded files are invisible,in other words, are not included in my asp.net project's folder.
You have a path string that shows where the files should be uploaded to. Are you sure that path is valid on the server? Have you checked other directories to see whether the files are stored elsewhere? Are you certain that the files are actually being uploaded?
-
HumaMunir wrote:
catch (Exception ex) { return ""; }
That's a very bad, really terrible, coding practice. Don't do so. An exception occured. You just swallowed it. Perhaps the user had no priviledges to write to that folder. Also note: how will you later be able to access those files? Do you have some database table or some other mechanism to find out which files exist and to generate the html links to them?
Bernhard Hiller wrote:
That's a very bad, really terrible, coding practice. Don't do so.
Thank a lot for the advice but I have a check I am handling it on button click for now, will change it once I get the uploading fixed.
Bernhard Hiller wrote:
Also note: how will you later be able to access those files? Do you have some database table or some other mechanism to find out which files exist and to generate the html links to them?
Following is my button click event, I hope this will help you understand the rest of the code and yes I am storing it in the database and displaying them on another page in a grid.
protected void btnAdd_Click(object sender, EventArgs e)
{
string isBest;if (cbIsBest.Checked) { isBest = "Yes"; } else { isBest = "No"; } string picPath = UploadPicture(); // uploads picture using file upload control and stores it in ImgNewsletter folder string newsletterPath = UploadNewsletter(); // uploads newsletter using file upload control and stores it in Newsletter folder if (picPath == "") { divError.InnerText = "Please select an image for the newsletter."; } if (newsletterPath == "") { divError.InnerText = "Please provide the e-copy of newsletter."; } else { try { string uploadedBy = Session\["Email"\].ToString(); if (dl.insertNewsletter(txtTitle.Text, ddlMonth.SelectedItem.ToString(), areaSummery.Text, picPath, newsletterPath, ddlCohort.SelectedItem.ToString(), isBest, uploadedBy)>0) { divSuccess.InnerText = "Thanks! Mahara Insight has been uploaded successfully."; divSuccess.Visible = true; } else { divSuccess .InnerText = "Sorry for inconvenience. Some error has occured. Please try later."; divSuccess.Visible = true; } } catch (Exception ex) { divError.InnerText = "Sorry for inconvenience. Some error has occured. Please try later."; } } }
Regar
-
The idea is that the admin will upload the newsletter, that will be shown to every user. This is not something exceptional, I have done this before using file upload. You can upload the files by giving a path and then can store the same path in the database to show them later. But this time all the uploaded files are invisible,in other words, are not included in my asp.net project's folder.
Regards HumaMunir
What the connection between show an uploaded file to everyone and to make a part of the project!!! You are talking nonsense here. Upload the file, store it anywhere you want (and can), probably store a reference in your database, then present a link to the uploaded file to everyone should see it...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
HumaMunir wrote:
his time all the uploaded files are invisible,in other words, are not included in my asp.net project's folder.
You have a path string that shows where the files should be uploaded to. Are you sure that path is valid on the server? Have you checked other directories to see whether the files are stored elsewhere? Are you certain that the files are actually being uploaded?
Thanks for the reply. Please check out this image, I dont think its the issue of path or privileges because the files are uploaded in the folder but they are not included in the project. https://drive.google.com/file/d/0Bw5Y6qnYiUrFRGxscjRVYUpXc0U/edit?usp=sharing[^]
Regards HumaMunir
-
What the connection between show an uploaded file to everyone and to make a part of the project!!! You are talking nonsense here. Upload the file, store it anywhere you want (and can), probably store a reference in your database, then present a link to the uploaded file to everyone should see it...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
Kornfeld Eliyahu Peter wrote:
What the connection between show an uploaded file to everyone and to make a part of the project!!!
You are talking nonsense here.
Upload the file, store it anywhere you want (and can), probably store a reference in your database, then present a link to the uploaded file to everyone should see it...This is my criteria to store my file in my project. I am not talking non sense. May be you are overwhelmed with your so called knowledge. That’s ok if you can’t solve my problem but please learn to behave!
Regards HumaMunir
-
Kornfeld Eliyahu Peter wrote:
What the connection between show an uploaded file to everyone and to make a part of the project!!!
You are talking nonsense here.
Upload the file, store it anywhere you want (and can), probably store a reference in your database, then present a link to the uploaded file to everyone should see it...This is my criteria to store my file in my project. I am not talking non sense. May be you are overwhelmed with your so called knowledge. That’s ok if you can’t solve my problem but please learn to behave!
Regards HumaMunir
HumaMunir wrote:
This is my criteria to store my file in my project
The funny thing that you are going with it again...Let put thing in order... Project - is a unit (probably more than on in a solution) that used to write code. After publishing (with or without compilation) it transforms to an application (called also site sometime). So how it can be a criteria that an uploaded file will be part of the project!!! No one can solve you a problem that by it's nature does not exist. Learn distinguish between project/application than you probably will solve your problem alone...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
Thanks for the reply. Please check out this image, I dont think its the issue of path or privileges because the files are uploaded in the folder but they are not included in the project. https://drive.google.com/file/d/0Bw5Y6qnYiUrFRGxscjRVYUpXc0U/edit?usp=sharing[^]
Regards HumaMunir
HumaMunir wrote:
but they are not included in the project.
Of course they are not, they are just files stored in a folder, they have nothing to do with any project. A project is just a concept used by Visual Studio to group a set of files and rules for compiling and linking into an executable or interpretable program. If you want these files added to your project (and I have no idea why you would), then you need to copy them manually into your build system and rebuild and republish your entire project. You seem to be confused between the development and execution phases of an application.
-
Thanks for the reply. Please check out this image, I dont think its the issue of path or privileges because the files are uploaded in the folder but they are not included in the project. https://drive.google.com/file/d/0Bw5Y6qnYiUrFRGxscjRVYUpXc0U/edit?usp=sharing[^]
Regards HumaMunir
Greetings. I think I see what the issue is here. The Solution Explorer does not work like Windows Explorer -- it looks like Windows Explorer -- BUT.... It is only going to show you files that you put there using Visual Studio. Try right clicking on that folder and select Refresh Folder. If those uploads worked -- the files will show up after you refresh. You cannot expect Visual Studio to include a file in your project just because it is in a folder in your project -- you must explicitly do that -- either by adding them using the Solution Explorer -- or, by refreshing the folder after this upload process. Also -- look at your try/catch again. You might just as well not use try/catch if you cannot tell that you threw an exception -- the catch block does nothing -- it returns in the same manner that the normal path does -- so all you have gained by using try/catch -- is that your function runs a little more slowly and .NET thinks that you handled the exception which makes it silent -- and likewise undetected. EDIT: Having read through the entire thread -- let me say a few things -- that are my opinion from many years of experience -- not all of it was wise, either. This is your project -- you do what makes sense to you -- but -- be very careful about assumptions that you make. I can see you possibly watching the process...looking at Solution Explorer -- and geting frustrated because your files are disappearing -- but, they are not disappearing -- they are simply not part of your project -- so they are not being displayed. That is why you are getting blowback from others about it -- they are not part of the project being built by Solution Explorer -- they are probably best described as input/output -- a product of the project, I suppose. So...I do not disagree with your folder structure -- it looks well thought out. However, you are making the assumption that Solution Explorer will list the content of the folder with no assistance from you -- and I learned that you must refresh that folder by making the same assumption -- so, I am telling you what I learned so that you can have your question answered and move on to writing your code. About the catch thing -- I also tend to litter my try/catch blocks and sometimes don't have much in the catch, but at a minimum I will put a breakpoint on a line of code in the catch, so that I still know that an exception occured. I am sure that you know -- if the permissions were not proper, and exception would have occurred -- access denied, I think -- right? Are yo