Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Christian Kragh 14 posts 34 karma points
    Nov 09, 2010 @ 07:57
    Christian Kragh
    0

    Template getting the userid and how to get the file size?

    Hey.

    I have a template that read all documents in a specific folder and list it to the user.

    Can i i my c# script getting the current userid to the script?

    It is the saveDir I will have to go to media\fd\<userid> media\fd\1022 ect.

    I try with saveDir = @"media\fd\"+@userid; and saveDir = @"media\fd\@userid"; but it dosen't work.

    How can i read the file size and creation date?

    My code is:

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Site.master" AutoEventWireup="true" %>
    <script runat="server">
      void Page_Load(object sender, EventArgs e) {
        string saveDir = @"media\fd\";
        string appPath = Request.PhysicalApplicationPath;
        bool dokdirexists = System.IO.Directory.Exists(@appPath + saveDir);
        bool Persdokdirexists = System.IO.Directory.Exists(@appPath + PerssaveDir);

        if (!dokdirexists) {
          System.IO.Directory.CreateDirectory(@appPath + saveDir);
        }

        string[] array1 = System.IO.Directory.GetFiles(@appPath + saveDir);
        string FileInDir = null;
        string TempFileName = null;
        string TempFilePath = null;
        string TempFileCreated = null;
        string TempFileSize = null;

        foreach (string name in array1) {
          TempFileName = name.Replace(appPath+saveDir,"");
          TempFilePath = name.Replace(appPath,"");
          TempFileCreated = "2010-10-29";
          TempFileSize = "200 kb";
          FileInDir = FileInDir + "<div><label class='ll'>" +TempFileCreated + "</label><label class='lr'>" + TempFileSize + "</label><a href='" + TempFilePath + "'>" + TempFileName + "</a> " + "</div>";
        }

        UploadStatusLabel.Text = FileInDir;
      }
    </script>
    <asp:content ContentPlaceHolderId="Content" runat="server">
      <h2>Fælles dokumenter</h2>
      <div class='filedirtop'><label class='ll'>Oprettet</label><label class='lr'>Størrelse</label>Filnavn</div>
      <asp:Label id="UploadStatusLabel" runat="server"></asp:Label>
      <h2>Personlige dokumenter</h2>
      <div class='filedirtop'><label class='ll'>Oprettet</label><label class='lr'>Størrelse</label>Filnavn</div>
    </asp:content>

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Nov 10, 2010 @ 13:21
    Tim
    0

    I can help with the file reading stuff,the mothod you are using to get the files only returns an array of file names. You need to use the Directory Info and File Info classes to get the data you require:

    DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/demos");
    FileInfo[] rgFiles = di.GetFiles("*.aspx");
    foreach(FileInfo fi in rgFiles)
    {
      Response.Write("<br><a href=" + fi.Name + ">" + fi.Name + "</a>");      
    }

    The file info object also contains the create date and filesize etc. Google "list files in directory c#" for a bunch of more detailed tutorials.

    For the user id, what sort of user do you mean? Are you referring to a back office user, or a front end member user?

    Cheers,

    Tim.

  • Christian Kragh 14 posts 34 karma points
    Nov 10, 2010 @ 14:06
    Christian Kragh
    0

    I refer to the front end members...

    I sovled the problem with personal folders this way...

    var member = System.Web.Security.Membership.GetUser();
    string PerssaveDir = @"media\fd\"+member+"\\";

    I reach the problem is that i was using this line:
    string PerssaveDir = @"media\fd\"+member+"\";

    The last "\" should be "\\".

    I look at your anser tomorrow.

    Best Regards
    Christian

Please Sign in or register to post replies

Write your reply to:

Draft