Pergunta

I'm writing custom module for upload image. After upload file to custom folder. When loading image, image's address is correctly but it doesn't show in image control.

How to show image in DotNetNuke custom module?

//Save Picture Code:

    fileuppic.PostedFile.SaveAs(MapPath("~/images/Hotels/" + filename));

//Load Picture Code:

  while (dr.Read())
    {
       imgpic.ImageUrl = MapPath("~/images/Hotels/") + dr["Picture"].ToString();
    }

//my ImageControl :
    <asp:Image ID="imgpic" runat="server" />
Foi útil?

Solução 2

You're not really using the file system as intended with DNN. Images should be managed through DNN's DotNetNuke.Services.FileSystem namespace and you're likely writing a lot of code you don't need to in order to save images as well (try the dnnFilePickerUploader control, it handles the upload and passes you a FileId). Once you have the FileId persisted with your object, you could use something like this to load the image:

private string GetPath(int fileId)
{
    StringBuilder sb = new StringBuilder("/Portals/");

    IFileInfo fi = FileManager.Instance.GetFile(fileId);
    sb.Append(fi.PortalId);
    sb.Append("/");
    sb.Append(fi.RelativePath);

    return sb.ToString();
}

Outras dicas

If you already have the fileId, you could just do:

VB.NET

Protected Function GetPath(fileId As Integer) As String

    Dim fi = FileManager.Instance.GetFile(fileId)
    Return FileManager.Instance.GetUrl(fi)

End Function

C#

private string GetPath(int fileId)
{
    var fi = FileManager.Instance.GetFile(fileId);
    return FileManager.Instance.GetUrl(fi);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top