fantasylan
asked on
How to get the entire file path from a FileUpload control in C sharp ASP.net
Hi,
I am using the FileUpload Control to attach emails in my application.
The problem is that I cant find out the entire file path and I need it so that the file can be attached to my email.
Thanks
I am using the FileUpload Control to attach emails in my application.
The problem is that I cant find out the entire file path and I need it so that the file can be attached to my email.
Thanks
string filePath = (System.IO.Path.GetFullPat h(FileUplo ad1.Posted File.FileN ame));
ASKER
Hi silemone,
I did what you suggested but instead of getting the actual location of the file, I was getting a path from inside visual studio as "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\gimp-2.6.e xe". When I tried to attach this I got a runtime error "Can't find this file. Make sure the path and file name are correct."
Also, I checked to see if the file actually existed in file path that was being returned from the expression you suggested and there was no such file in the folder.
I did what you suggested but instead of getting the actual location of the file, I was getting a path from inside visual studio as "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\gimp-2.6.e
Also, I checked to see if the file actually existed in file path that was being returned from the expression you suggested and there was no such file in the folder.
? wow...that's odd.
are you running a local copy of your program? maybe visual studios is working off of temporary files...bu tstill doesn't explain why it would give that address if its not correct...
ASKER
I am running the application off Visual Studio.
Here is the code snippet I have written :
string fpath = System.IO.Path.GetFullPath (FileUploa d1.PostedF ile.FileNa me);
newAttachmentCell.Text = FileUpload1.FileName.ToStr ing();
newAttachmentRow.Cells.Add (newAttach mentCell);
AttachmentTable.Rows.Add(n ewAttachme ntRow);
eMail.Attachments.Add(fpat h, OlAttachmentType.olByValue , 1, FileUpload1.FileName);
Thanks
Here is the code snippet I have written :
string fpath = System.IO.Path.GetFullPath
newAttachmentCell.Text = FileUpload1.FileName.ToStr
newAttachmentRow.Cells.Add
AttachmentTable.Rows.Add(n
eMail.Attachments.Add(fpat
Thanks
will the file always be located at a certain directory because you could always hardcode that part...
filePath = @"c://....";
filePath = @"c://....";
ASKER
yes ... i could always do that ;) ... but I wanted to implement it using the FileUpload box.
string strFilePath = Server.MapPath("~/UploadFi le") + "\\" +FileUpload1.FileName;
ASKER
Hi RajasekaranMoorthy,
The code that you posted points me to the directory where my Project Folder is located and not the actual file and I try to pass the the path of the file as an attachment to the email, I get a file not found runtime exception.
The code that you posted points me to the directory where my Project Folder is located and not the actual file and I try to pass the the path of the file as an attachment to the email, I get a file not found runtime exception.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.