Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner


Allows uploads of only jpg files


<html>
<head>
<script language="c#" runat="server">
private void Upload(Object Source, EventArgs e)
{
  if (myFile.PostedFile != null)
  {
    int intFileLength;
    string ImgFileNamePath;
    string ImgFileName;
    if (myFile.PostedFile.ContentType != "image/pjpeg")
    {
      lbResult.Text = "Tipo di file non valido";
    }
    else
    {
      if (myFile.PostedFile.ContentLength > 50000)
      {
        lbResult.Text = "File troppo grande";
      }
      else
      {
        try
        {
          ImgFileNamePath = myFile.PostedFile.FileName;
          intFileLength = Instr(1, StrReverse(ImgFileNamePath), "\\");
          ImgFileName = Mid(ImgFileNamePath, (Len(ImgFileNamePath)-intFileLength)+2);
          myFile.PostedFile.SaveAs("c:\\wwwroot\\sito\\immagini\\" & ImgFileName);
          lbResult.Text = "File salvato";
        }
        catch (Exception ex)
        {
          lbResult.Text = "Errore nel salvataggio:<br>" & ex.Message;
        }
      }
    }
  }
}
</script>
</head>
<body>
<form name="Form1" runat="server" ID="Form1">
<INPUT id="myFile" type="file" name="myFile" runat="server"><BR>
<INPUT id="Button1" type="button" value="Upload" name="Button1" runat="server" OnServerClick="Upload"><BR><BR>
<asp:Label ID="lbResult" Runat="server"></asp:Label>
</form>
</body>
</html>



Download Code...


Print Page


 








Page top

risorse per webmaster