Wednesday, September 08, 2010

Viewing Category


File in DNN

 

    22
    Gần đây, có 1 bạn hỏi cách làm sao để khi dùng url control của DNN để upload 1 file, ta luôn đưa file đó vào 1 folder mặc định, được xác định trước. Mình đã thử nghiên cứu trên url control. Nhưng có vẻ hơi bị khó. Và mình đã quay lại với control FileUpload của ASP.NET. Và nó có thể thực hiện dễ dàng.
    <asp:FileUpload runat="server" ID="fu1" />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    protected void Button1_Click(object sender, EventArgs e)
            {
                fu1.PostedFile.SaveAs(Request.PhysicalApplicationPath+@"Portals\0\"+ System.IO.Path.GetFileName(fu1.PostedFile.FileName));           
            }
    Ở đây, mình làm test nên đưa nó vào Portals/0. Còn bạn muốn dynamic hơn thì có thể viết thêm vài dòng code nữa. ^_^
    Link tham khảo từ:

     

    [Read the rest of this article...]

    Posted in: File in DNN
    28

    Lệnh lấy đường dẫn tới Module:

    ModulePath
    Lệnh lấy đường dẫn tới Portal:
    PortalSettings _portalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
     _portalSettings.HomeDirectory
    Lấy đường dẫn tới Application:
    Request.ApplicationPath
    Ngoài ra có thể chia cắt lại đường dẫn ở ModulePath để lấy đường dẫn Application cũng được.
    Để lấy chính xác đường dẫn thì cần thêm Server.MapPath cho mấy thằng trên.
    Ví dụ cụ thể:
    Module: /MySiteDNN1/DesktopModules/MyImportFileDemo/
    Portals: /MySiteDNN1/Portals/0/
    Application: /MySiteDNN1

    [Read the rest of this article...]

    Posted in: File in DNN
    HomeTrangITForum
    Copyright 2010 by Nguyễn Minh ĐứcDesigned by DyNNamiteTerms Of UsePrivacy Statement