private void ProcessUpload()
    {
        TemporaryIdentity tempId = new TemporaryIdentity(Int32.Parse(this.TemporaryDocumentIdentity.Text));

        if (tempId.Identity == 0)
        {
            // Ok, storing the temporary id in the page state is REALLY ugly.
            // How are you supposed to solve this class of problems, where you
            // need to persist data on a page for later processing?

            tempId = TemporaryIdentity.GetNew();
            this.TemporaryDocumentIdentity.Text = tempId.Identity.ToString();
        }

        string serverPath = @"C:\Data\Uploads\PirateWeb";  // TODO: Read from web.config

        foreach (UploadedFile file in this.Upload.UploadedFiles)
        {
            string clientFileName = file.GetName();
            string extension = file.GetExtension();

            Document newDocument =
                Document.Create (Guid.NewGuid().ToString() + ".tmp", clientFileName,
                                file.ContentLength, string.Empty, tempId, _currentUser);

            string serverFileName = String.Format("document_{0:D5}_invoicebyperson_{1:D6}{2}", newDocument.Identity, _currentUser.Identity, file.GetExtension().ToLower());
            file.SaveAs(serverPath + Path.DirectorySeparatorChar + serverFileName);

            newDocument.ServerFileName = serverFileName;

            File.Delete(serverPath + Path.DirectorySeparatorChar + file.GetName());
        }

        this.GridInboundInvoices.Reload();
    }
Esempio n. 2
0
    private void ProcessUpload()
    {
        TemporaryIdentity tempId = new TemporaryIdentity(Int32.Parse(this.TemporaryDocumentIdentity.Text));

        if (tempId.Identity == 0)
        {
            // Ok, storing the temporary id in the page state is REALLY ugly.
            // How are you supposed to solve this class of problems, where you
            // need to persist data on a page for later processing?

            tempId = TemporaryIdentity.GetNew();
            this.TemporaryDocumentIdentity.Text = tempId.Identity.ToString();
        }

        string serverPath = @"C:\Data\Uploads\PirateWeb";  // TODO: Read from web.config

        foreach (UploadedFile file in this.Upload.UploadedFiles)
        {
            string clientFileName = file.GetName();
            string extension      = file.GetExtension();

            Document newDocument =
                Document.Create(Guid.NewGuid().ToString() + ".tmp", clientFileName,
                                file.ContentLength, string.Empty, tempId, _currentUser);

            string serverFileName = String.Format("document_{0:D5}_expensebyperson_{1:D6}{2}", newDocument.Identity, _currentUser.Identity, file.GetExtension().ToLower());
            file.SaveAs(serverPath + Path.DirectorySeparatorChar + serverFileName);

            newDocument.ServerFileName = serverFileName;

            File.Delete(serverPath + Path.DirectorySeparatorChar + file.GetName());
        }
    }