1 Replies - 879 Views - Last Post: 07 July 2013 - 01:20 PM Rate Topic: -----

#1 raminr63   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 20-May 11

select multiple files and make multiple output

Posted 07 July 2013 - 11:48 AM

Hi
guys i am beginner in c# and wrote a code to make .lzma files but with this code i can select only one file and also make only one output for my project but i need your helps how i can select multiple files (include folders and sub folders) and must be i say i know about "dialog.Multiselect = true;" but i am confuse how make multiple select and output for my project.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;

namespace UpdateBuilder
{
    public partial class MainFrm : Form
    {

        public string fileName = "";
        public string output = "";

        public MainFrm()
        {
            InitializeComponent();
        }

        private void browseBtn_Click(object sender, EventArgs e)
        {
            // Show a file browsing dialog
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "All files (*.*)|*.*";
            dialog.InitialDirectory = Directory.GetCurrentDirectory();
            dialog.Multiselect = true;
            dialog.Title = "Select a file to build";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                // Place the selected file's path in the input textbox
                inBox.Text = dialog.FileName;
                fileName = dialog.SafeFileName;
            }
        }

        private void buildBtn_Click(object sender, EventArgs e)
        {
            if (inBox.Text != "")
            {
                try
                {
                    string path = @"info";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    // Disable all controls
                    inBox.Enabled = false;
                    browseBtn.Enabled = false;
                    buildBtn.Enabled = false;

                    // Start the converion utility
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = "lzma.exe";
                    startInfo.Arguments = "e " + inBox.Text + " " + inBox.Text + ".lzma -d21";
                    startInfo.CreateNoWindow = true;
                    startInfo.WindowStyle = ProcessWindowStyle.Hidden;

                    using (Process p = Process.Start(startInfo))
                    {
                        // And wait for it to finish
                        while (!p.HasExited)
                        {
                            Thread.Sleep(100);
                        }
                    }

                    // Generate that final string
                    FileInfo inFile = new FileInfo(inBox.Text);
                    FileInfo outFile = new FileInfo(inBox.Text + ".lzma");
                    output = "<ContentFile Name=\"" + fileName + "\" Size=\"" + inFile.Length.ToString() + "\" SHA1Hash=\"" + HashCalc.GetSHA1Hash(inBox.Text) + "\" CompressedSize=\"" + outFile.Length.ToString() + "\" />";

                    // Re-enable the controls
                    inBox.Enabled = true;
                    browseBtn.Enabled = true;
                    buildBtn.Enabled = true;

                    // Show notice and copy output to clipboard
                    // Clipboard.SetText(output);
                    // System.IO.File.WriteAllText("C:\\info.xml", output); //write single line

                    MessageBox.Show("Build succeeded.\nCopied output to clipboard.");
                    File.AppendAllText(@"info\\info.xml", output + Environment.NewLine);
                }
                catch
                {
                    MessageBox.Show("Sorry we cann't make output folder pleas check permission.");
                }
            }
            else
            {
                MessageBox.Show("Please select a file to build.");
            }
        }
    }
}






Is This A Good Question/Topic? 0
  • +

Replies To: select multiple files and make multiple output

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7187
  • View blog
  • Posts: 24,356
  • Joined: 05-May 12

Re: select multiple files and make multiple output

Posted 07 July 2013 - 01:20 PM

If you looked at the documentation for MultiSelect, you would have found sample code:
http://msdn.microsof...ultiselect.aspx

<rant>
Intellisense is going to be the end of us all.
</rant>

This post has been edited by Skydiver: 07 July 2013 - 01:21 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1