Fileupload problem, please help.
-
Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.
-
Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.
The FileUpload control has a SaveAs(string path) method. You can use that method to save the file to any path using any filename you want. Just make sure ASP.NET has permissions to write to that path. So, you can do something like this to save the uploaded file to the uploads folder in the root of your website:
fileUpload1.SaveAs(Server.MapPath(“~/uploads/”)
- System.IO.Path.GetFilename(fileUpload1.FileName));
-
The FileUpload control has a SaveAs(string path) method. You can use that method to save the file to any path using any filename you want. Just make sure ASP.NET has permissions to write to that path. So, you can do something like this to save the uploaded file to the uploads folder in the root of your website:
fileUpload1.SaveAs(Server.MapPath(“~/uploads/”)
- System.IO.Path.GetFilename(fileUpload1.FileName));
thank u for ur reply i've tried that, still at my database i get only the file's name without the path ~/folder/... i need to add it as a string before the file's name. or! if there was a way for inserting like an auto text option to that column each time i insert the data (before the file name). any idea how? thanks
-
Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.
Do not post to multiple forum :mad:
I know the language. I've read a book. - _Madmatt
-
Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.
-
im sorry actually i disabled the code lol now im running this code ugave me and im getting some errors. System.IO.Path' does not contain a definition for 'GetFilename' The name 'fileUpload1' does not exist in the current context
Hi there, the ID of your upload Control is "FileUpload1" in your example, not "fileUpload1". Always pay attention to the letter case. Same with GetFilename. The Method is written "GetFileName". What the upload control does, is the following: it saves your selected file to the file-system. No path-saving to your database at this point. Where are you saving the path to your db? there you have to save the virtual path of your upload folder in addition to your filename. Just concat the strings there. Good Luck
-
Hi there, the ID of your upload Control is "FileUpload1" in your example, not "fileUpload1". Always pay attention to the letter case. Same with GetFilename. The Method is written "GetFileName". What the upload control does, is the following: it saves your selected file to the file-system. No path-saving to your database at this point. Where are you saving the path to your db? there you have to save the virtual path of your upload folder in addition to your filename. Just concat the strings there. Good Luck
Hi michaelschmitt, thank you for ur reply and for ur information :) the letters are actualy as they should be. ____ I still cannot get it fixed even after adding the System.IO.Path.. // FileUpload1.PostedFile.SaveAs(Server.MapPath(("~/photo/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)))); //
-
Hi michaelschmitt, thank you for ur reply and for ur information :) the letters are actualy as they should be. ____ I still cannot get it fixed even after adding the System.IO.Path.. // FileUpload1.PostedFile.SaveAs(Server.MapPath(("~/photo/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)))); //
What i was trying to say is that your posted code does not include any interaction with your access database. It just takes the selected filename from your upload control and saves this file to the desired folder. This code alone would not insert the filename into your access-database table. To clarify: "~/photo/" is the virtual path of your upload folder. Server.MapPath is needed to tranform this to the corresponding physical directory on your web-server (e.g.: c:\http\mysite\photo). FileUpload1.SaveAs(...) saves your file to this folder. Use string virtualFilePath = "~/photo/" + FileUpload1.FileName; to get your desired Path und save it to your database.
modified on Monday, March 29, 2010 9:43 AM