Displaying PDF file size on a NewsList control (FileInfo)

Hello, I have a NewsList control that lists information about documents such as title, date of publication, etc and a link to a pdf file. I display all of these values by using the container sintax as follows: <%#getlink(container.currentpage)%> , (<%# container.currentpage["datepublication"] !="null?((DateTime)Container.CurrentPage["DatePublication"]).ToString("d"):" "no publication data available"%>) File Size: <%#container.currentpage["varfilepath"]%> kb I am trying to extract the file size of the file which I will then display in the last line inside the NewsTemplate. Does anyone know how to do this using the Container reference as it is a list inside a NewsList? I researched and wonder if the answer is in the FileInfo class. Maybe something along the following could work but it isn't. ascx <%# getfilelength(container.currentpage)%> kb ascx.cs public string GetFileLength(PageData pdFileInfo) { FileInfo fi = new FileInfo(pdFileInfo.Property["varFilePath"].ToString()); return fi.Length.ToString(); } Any better ideas anyone? Thanks. Victor
Mar 25, 2008 18:36
I ended up using the following code: aspx , <%# GetFileLength(Container.CurrentPage["varFilePath"].ToString())%> aspx.cs public string GetFileLength(string FilePath) { string _getFileInfo = ""; try { FileInfo finfo = new FileInfo(Server.MapPath(FilePath)); long FileInKB = finfo.Length / 1024; _getFileInfo = FileInKB.ToString(); } catch (NotSupportedException) { } catch (ArgumentException) { } catch (IOException) { } catch(HttpException) { } return _getFileInfo; }
Mar 25, 2008 18:47
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.