Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...
i have uploaded a file...
i want to store those info about file in my database....
like
file name,
file type,
extension,
size,
file path.
and also i want to store it in database...
i know to identify the filename:
fname.InnerHtml=MyFile.PostedFile.FileName

for size:
clength.InnerHtml=MyFile.PostedFile.ContentLength...

can u say how to do?
Posted
Updated 2-Nov-11 0:55am
v2

use FileInfo Class to get the upload file details.

check this link
http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx[^]
 
Share this answer
 
Comments
Raghupathiraja 2-Nov-11 7:24am    
how to store in database
sabbi26 2-Nov-11 7:25am    
what actually u need to store in Database (File or FilePath)
Raghupathiraja 2-Nov-11 7:32am    
file details and file path...
when i click view button the file contents deplay in it?
use the HttpPostedFile and following properties :
ContentLength: size of uploaded file in bytes
ContentType: type of uploaded file, i.e. "image/gif"
FileName: full path to uploaded file on client's system,

or get everything at :File Upload with ASP.NET[^]
 
Share this answer
 
v4
use
C#
FileInfo fi = new FileInfo(filepath);
            fi.Extension;

and U can find many more it will solve ur requirement
 
Share this answer
 
v2
Comments
Raghupathiraja 2-Nov-11 7:17am    
i can't gets u friend...
can u say detaily?
Menon Santosh 2-Nov-11 8:39am    
using System.IO
FileInfo fi = new Fileinfo([your filename + path])
fi.Extension // get file extension
fi.length // get file length/size in bytes
fi.fullname //get full path
 
Share this answer
 
hi,

use this below code to upload file in folder

public bool fnFileUpload(string FilePath, FileUpload FileUpload)
{ 
BinaryReader br = new BinaryReader(FileUpload.PostedFile.InputStream);
FileStream fstm = new FileStream(FilePath, FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fstm);
byte[] buffer = br.ReadBytes(FileUpload.PostedFile.ContentLength);
br.Close();
bw.Write(buffer);
bw.Flush();
bw.Close();
return true;         
}


In the above code filepath is nothing but filename with the directory location ex:c:\temp\Myfile.txt

the code will save the file in file system only.

Send the FilePath value to the database and retrieve this info when read is required

I hope this will help
 
Share this answer
 
Comments
Raghupathiraja 2-Nov-11 7:46am    
THANKS ...
oh if i send the file path means it ill retrieve the contents ah...
thanks....
i have doubt that how to store in database
file name, size, type, path.... and all...
how to do this?
sabbi26 2-Nov-11 8:29am    
simply send the path value as a string to the database and save in the table column of type Varchar(50).

when reading the file simply "Select FilePath From Table1" it gets file Path than u need to pass that FilePath as a url to linkButton or hyperlink what ever it is. That's it nothing more
Raghupathiraja 2-Nov-11 14:05pm    
thank u friend...
its really good...
Raghupathiraja 3-Nov-11 1:36am    
call the function in the submit button or what to do for it?

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