"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Showing posts with label FileInfo. Show all posts
Showing posts with label FileInfo. Show all posts

Sunday, April 15, 2012

Deleting a file from the server

hi Everybody,

Some times v may have to replace our old file ( what b the file format) with new one.Just like updating Bio in a job Portal an example. for that v need to find whether it exist a file  On that name if v find. v need to delete it.Some server will done this job automatically some times it may throw an error "Access denied".So let's don't take that risk :)

Friday, September 16, 2011

Binding or display image having zoom effect from folder

Hi *.*,
As a continuation of my previous post. Now i'm binding images from folder.

Code 
    private class ImageFileInfo
    {
        public string FileName { get; set; }
    }

    public void limage()
    {
        string imgFolder = HttpContext.Current.Request.PhysicalApplicationPath + @"img\";
        string[] fileEntries = Directory.GetFiles(imgFolder);
        List<ImageFileInfo> mylist = new List<ImageFileInfo>();
        foreach (string fName in fileEntries)
        {
            string d = System.IO.Path.GetFileName(fName);
            mylist.Add(new ImageFileInfo { FileName = d });
        }
        dtagrid.DataSource = mylist;
        dtagrid.DataBind();
    }
 

On HTML
 
                <asp:DataList ID="dtagrid" runat="server" RepeatColumns="5" RepeatDirection="Horizontal">
                    <ItemTemplate>
                        <li><a href='img/<%# Eval("FileName") %>'>
                            <img src='img/<%# Eval("FileName") %>' alt="" /></a></li>
                    </ItemTemplate>
                </asp:DataList>

 U can download a demo from here
 Stay Tune...
Have a nice day... 'N happy Coding :)

Friday, May 6, 2011

Getting File type or Getting file extension

 Getting File type or Getting file extension is done by some many ways a few is listed here ::-
  • string fileExtension = System.IO.Path.GetExtension(@"C:\MyFolder\MyFile.jpg"
  • System.IO.FileInfo f = new System.IO.FileInfo(Server.MapPath("~/MyFolder/MyFile.jpg"));
    string extension = f.Extension;
 Over here i prefer the second method.

Stay tune...
Have a nice day... 'N happy Coding :)