Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me. i know its a simple problem only but how do i insert only a file extension to the database? what should i write in the insert statement? i wanna insert a file extension such as .pdf, .docx, etc.. i've already upload the file so now i need to insert that file extension into another field in the same table.
Posted
Updated 18-Jul-13 18:29pm
v3
Comments
Ron Beyer 18-Jul-13 23:36pm    
Its not real clear what you are trying to do, you want to insert the file extension, like the text ".pdf" into a database? Or you want to insert the contents of a file with a particular extension in a database? Please use the Improve Question link to add more information.
Mare7 19-Jul-13 0:06am    
owh sorry. i wanna add the extension like .pdf or .docx ...

1 solution

use the following code.. insert the value of variable extension to the database
C#
string extension = System.IO.Path.GetExtension(filename);
 
Share this answer
 
Comments
Mare7 19-Jul-13 2:39am    
thank you for your response. but can u please explain it to me how to implement this in my code?
my insert statement goes like this

("Insert Into saoCmpntFile (CmpntID, FileName, Description,FileType, FileExtension, cid, cdt) Values([/" & txtID.Value & "/],[/" & NewFile & "/],[/" & txtFileDesc.Text & "/],[/C/], "THIS IS WHERE I SHOULD PUT THE VALUE OF FILE EXTENSION" [/" & User.Identity.Name & "/], GetDate())")

how do i do the declaration or such to get the value?

THANK YOU IN ADVANCE..
Zafar A khan 19-Jul-13 2:49am    
yes you have already highlighted where should put that. is the correct but you have two fields FileType and FileExtension.. first you have to provide the filetype then extension
dim filetype as string="";
dim extension as string=System.IO.Path.GetExtension(filename)
if extension=".doc"
then
filetype="Ms Word"
else if extension=".xls"
then
filetype=".excel"
end if
("Insert Into saoCmpntFile (CmpntID, FileName, Description,FileType, FileExtension, cid, cdt) Values([/" & txtID.Value & "/],[/" & NewFile & "/],[/" & txtFileDesc.Text & "/],[/" & filetype & "/],[/" & extension & "/], [/" & User.Identity.Name & "/], GetDate())")
Mare7 19-Jul-13 3:01am    
owh ok..sorry2..its my mistake. i put the code before i declare the filename. now it works already. thanks a lot. ur da best!!
Zafar A khan 19-Jul-13 3:05am    
if it helped you vote it. may this code help someone other. vote it and mark as solution . thanks... glade to help you.
Mare7 19-Jul-13 2:58am    
thanks you very much. i think this code would work already only when i rewrite it in my code, the ".GetExtension" will be detected as undeclared element. do i need to declare anything else?

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