Access file info

2 posts, 0 answers
  1. Joseph
    Joseph avatar
    21 posts
    Member since:
    Mar 2013

    Posted 04 Sep 2013 Link to this post

    There is a folder for my project that has files uploaded in it. From C# I am trying to access the required file using the name and hence its informations using code.
    FileInfo myfile=new FileInfo(filename);
    The var filename is a string with the name of one of the uploaded file but running the app gives me Access denied error. Any special permissions is there to access the directory with the file.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Sep 2013 Link to this post

    Hi Joseph,

    You cannot access files you've placed in the project using the FileInfo object. Instead you create a Uri to access it.

    Its not clear from your question which project you've place the file in. If you have placed it in the Silverlight project then it ought to end up as content in the Xap where you can use StreamResourceInfo to access it as follows.

    C#:

    StreamResourceInfo fileContentInfo = Application.GetResourceStream(new Uri(filename, UriKind.Relative));

    Also now the file content could be accessed as follows.

    C#:
    Stream fileStream = fileContentInfo.Stream;

    Thanks,
    Princy.

  3. DevCraft banner
Back to Top