Jump to content

Folderbrowser


korasoglu
 Share

Recommended Posts

Arkadaşlar en son açılan klasörü hatırlamsını nasıl yapabilirim. ve varsayılan klasör nasıl tanımlarım.

 

            FolderBrowserDialog dlg = new FolderBrowserDialog();
            dlg.Description = @"Klasör Seçiniz";
            if (dlg.ShowDialog() == DialogResult.OK)

Link to comment
Share on other sites

        string yol = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // seçilen yolu kaydetmek için global değişken (form kapanana kadar geçerlidir.)
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            dlg.SelectedPath = yol; // kaydediler yolu al
            dlg.Description = @"Klasör Seçiniz";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                yol = dlg.SelectedPath; // yolu kaydet
                // kodlar
            }
        }
Link to comment
Share on other sites

regedite kayıt edilip çekilse o zaman format atılana kadar hatırlar. mantığı anladım bir araştırıyım.


Belki işine yarayan olur.

 

            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("DENEME1");
            key.SetValue("EKLE", "BIR");
            key.Close();
            
            RegistryKey key2 = Registry.CurrentUser.OpenSubKey(@"DENEME1");
            object aa = key2.GetValue("EKLE");
            MessageBox.Show(aa.ToString());
            key2.Close();

Link to comment
Share on other sites

Peki o zaman yönetici olarak nasıl çalıştırırız.

 

Edit:

 

Projenizi kodlarken, menüden Açılan dosyada şu satırı bulun;

<requestedExecutionLevel>

Şununla değiştirin;

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

 

Böyle yapılıyormuş.

Edited by korasoglu
Link to comment
Share on other sites

Bunu kendine göre uyarlarsan sorun çıkmaz ;

string Path = ""; 
string xmlpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Settings.xml";       

        private void xmlOKU()
        {
            try
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(xmlpath);
                XmlNodeList Settings = xml.SelectNodes("//Settings");
                foreach (XmlNode Setting in Settings)
                {
                    Path = Setting.SelectSingleNode("Path").InnerText;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void xmlYAZ(newPath)
        {
            try
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(xmlpath);
                XmlNode nodeToFind;
                nodeBUL = xml.SelectSingleNode("//Settings");

                if (nodeBUL == null)
                {
                    XmlElement newcatalogentry = xml.CreateElement("Settings");
                    XmlElement Pathstr = xml.CreateElement("Path");
                    Pathstr.InnerText = newPath;
                    newcatalogentry.AppendChild(Pathstr);
                    xml.DocumentElement.InsertAfter(newcatalogentry, xml.DocumentElement.LastChild);
                    xml.Save(xmlpath);
                }
                else
                {
                    foreach (XmlElement element in xml.SelectNodes("//Settings"))
                    {
                        element.SelectSingleNode("//Path").InnerText = newPath;
                        xml.Save(xmlpath);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void xmlOLUSTUR()
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                XmlElement rootNode = xmlDoc.CreateElement("root");
                xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
                xmlDoc.AppendChild(rootNode);
                xmlDoc.Save(xmlpath);
            }
            catch (XmlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            dlg.SelectedPath = Path;
            dlg.Description = @"Klasör Seçiniz";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                xmlYAZ(dlg.SelectedPath);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (File.Exists(xmlpath))
            {
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(xmlpath);
                    XmlElement root = xmlDoc.DocumentElement;
                    if (root != null)
                    {
                        xmlOKU();
                    }
                    else
                    {
                        xmlOLUSTUR();
                        xmlOKU();
                    }
                }
                catch (XmlException ex)
                {
                    xmlOLUSTUR();
                    xmlOKU();
                }
            }
            else
            {
                xmlOLUSTUR();
                xmlOKU();
            }
          }
Edited by muratboy31
Link to comment
Share on other sites

Nerede hata yapıyorum anlamadım bir çalışıyor bir çalışmıyor.

 

public static string yol = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

 

void listele()
        {
            RegistryKey key2 = Registry.CurrentUser.OpenSubKey(@"Takip");
            if (key2 == null)
            {
                key2.Close();
                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Takip");
                MessageBox.Show(yol);
                key.SetValue("Klasor", yol.ToString());
                key.Close();
            }
            else
            {
            object aa = key2.GetValue("Klasor");
            yol = aa.ToString();
            MessageBox.Show(yol);
            key2.Close();
            }
        }

 

listele();
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.SelectedPath = yol;
            dialog.Description = "Seçim Yapınız";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                yol = dialog.SelectedPath;
                MessageBox.Show(yol);
                Microsoft.Win32.RegistryKey key6;
                key6 = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Takip");
                key6.SetValue("Klasor", yol);
                key6.Close();

           }

Link to comment
Share on other sites

Bence harici bi xml dosyası ile uğraşmak bu durum için fazla komplike bir iş. Daha önce paylaştığım http://www.tnctr.com/topic/278977-film-ysimlendirici-20-kaynak-kod/ konusundaki programda şöyle ufak bir özellik vardı: Bir settings dosyası oluşturup böyle ufak bilgileri oraya kaydedip yine ordan çekmek. Projeyi indirdiğin zaman da göreceksin, proje dosyasında (Visual Studio'da açtığında) Ayarlar.Settings dosyası var. Çift tıklandığında bir sürü girdi göreceksin, bunlardan biri startup_folder. Tipi string scope'u user falan filan. Sen de kendi projende böyle girdi oluşturup istediğini yapabilirsin. Kod düzeyinde ise şöyle kullanılıyor;

 

yol = Ayarlar.Default.startup_folder; // get işlemi

 

Set içinse şöyle yapabilirsin;

 

Ayarlar.Default.startup_folder = "yeni_yolun_neyse" // set işlemi
Ayarlar.save()

(Değişkenleri, stringleri falan uygun bir şekilde değiştirebileceğini varsayıyorum.)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...