Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET ASP.NET Application – Text File Generation Then Zip Then Download with No File System Access

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20099 |

    Hello,

    Convinced boss to purchase. Love what I have been able to do so far.

    Have a problem that I cannot seem to find an answer to and cannot figure out.

    Need an ASP.NET (C# preferred) code snippet or sample that does the following things:

    1. Create 1 to many uniquely named text (*.csv) files in memory (MemoryFolder). Not on server file system. Write lines of text to files using something similar to System.IO.Streamwriter.Writeline.
    2. Zip up these text files into file on same MemoryFolder. Again not on server file system.
    3. Download resulting zip to end user.

    I have the above working using the server file system for text file generation, zip file generation, and subsequent zip file download to web page end user. Requires the web application’s IIS App Pool to run under a security context with Write permissions to file system folder – I want to eliminate this requirement and use the MemoryFolder and MemoryFile constructs. I can supply this code if needed.

    Thank you.

    Imported from legacy forums. Posted by Blue67 (had 2255 views)

    User (Old forums)
    Member
    Post count: 23064

    You can do something like the following :

    private static void run()

    {

        MemoryFolder memFolder = new MemoryFolder( @”Ram:\csvFolder” );

        for( int i = 0; i < 4; i++ )

        {

            MemoryFile csvFile = memFolder.CreateFile( i.ToString() + “.csv”, true ) as MemoryFile;

            using( StreamWriter writer = new StreamWriter( csvFile.OpenWrite( true ) ) )

            {

                writer.WriteLine( “this is a test of file #” + i.ToString() );

            }

        }

        MemoryFile memoryZip = new MemoryFile( @”Ram:\archive.zip” );

        ZipArchive archive = new ZipArchive( memoryZip );

        archive.TempFolder = new MemoryFolder();

        memFolder.CopyFilesTo( archive, true, true );

        archive.CopyFilesTo( new DiskFolder( @”D:\Temp\memFolder\” ), true, true );

        //you can use memoryZip.OpenRead() to get the stream to download your file to the user web page

    }

    This should do everything in memory.

    Imported from legacy forums. Posted by André (had 2845 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.