2

I'm developing a multilanguaged comics website and all the inserted comics must be in english and portuguese.

I've got success on managing multiple titles doing so:

ComicViewModel.cs:

public class ComicViewModel
{
    [Key]
    public int Id { get; set; }

    [Required(ErrorMessage="A data não pode ficar em branco.")]
    [DisplayName("Data")]
    public DateTime Date { get; set; }

    public IList<LocalizedTextViewModel> Titles { get; set; }
}

LocalizedTextViewModel.cs:

public class LocalizedTextViewModel
{
    public CultureViewModel Culture { get; set; }

    [Required(ErrorMessage = "Este campo não pode ficar em branco.")]
    public string Text { get; set; }
}

CultureViewModel.cs:

public class CultureViewModel
{
    public int Id { get; set; }
    public string Abbreviation { get; set; }
    public string Name { get; set; }

    public CultureViewModel() { }

    public CultureViewModel(Database.Culture culture)
    {
        Id = culture.Id;
        Abbreviation = culture.Abbreviation;
        Name = culture.Name;
    }
}

The problem is I can't figure out how to manage the comic images upload. I need upload more than one image, each one referenced to it's language.

Anyone has any ideas?

1
  • I saw here a way to handle uploaded files. But using an IEnnumerable I can't know in which language is each file. Commented Sep 13, 2010 at 13:26

1 Answer 1

1

Here's an example for uploading multiple files:

The Html:

<% using (Html.BeginForm("Upload", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
{%><br />
    <input type="file" name="files" id="file1" size="25" />

    <input type="file" name="files" id="file2" size="25" /> 

    <input type="submit" value="Upload file" />      
<% } %>   

The Controller :

[HttpPost]
public ActionResult Upload()
{
    foreach (string inputTagName in Request.Files)
    {
        HttpPostedFileBase file = Request.Files[inputTagName];
        if (file.ContentLength > 0)
        {
            string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads")
                    , Path.GetFileName(file.FileName));
            file.SaveAs(filePath);
        }
    }

    return RedirectToAction("Index");
}

Update : Getting some information about the uploaded file

The following example shows how you can get the name/type/size/extension of a submitted HttpPostedFileBase file.

string filename = Path.GetFileName(file.FileName);

string type = file.ContentType;

string extension = Path.GetExtension(file.FileName).ToLower();

float sizeInKB = ((float)file.ContentLength) / 1024;

suppose that you uploaded the file somePicture.jpeg the output will be.

filename  > somePicture.jpeg
type      > image/jpeg
extension > jpeg
sizeInKB  > // the file size.
Sign up to request clarification or add additional context in comments.

3 Comments

Ok it gets the images, but I need to know in which culture is each image. How can I reconize that? Can I change the name attribute on the form?
@Rodrigo Waltenberg: I hope my update has the answer to your first question and About the name attribute you can change it to whatever u want.
Your answer solves my question. But I think I didn't express myself well... I need it inside a ViewModel so doing this way doesn't work for me. I'll mark this question as solved and rebuild my question in another thread. thanks anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.