Kaydol:
Kayıt Yorumları
(
Atom
)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace C_Sharp_Form_Masaustu_Kisa_Yol_Olusturma
{
public partial class Form1 : Form
{
private System.Windows.Forms.Button btnShortCut;
private System.Windows.Forms.Button btnProgramShortCut;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtPath;
private System.Windows.Forms.TextBox txtProgramName;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3;
public Form1()
{
InitializeComponent();
}
private void btnShortCut_Click(object sender, EventArgs e)
{
//oluşturmak istediğiniz kısa yolun bağlantı ismini ve kısa yolun
//açacağı dosyanın adresini yazın.
if (txtName.Text.Trim() == "")
MessageBox.Show("Kısayol ismi girmelisiniz.", "Uyarı",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
else if (txtPath.Text.Trim() == "")
MessageBox.Show("Kısayol oluşturulacak dosyanın adresini girmelisiniz.",
"Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
appShortcutToDesktop(txtName.Text.Trim(), @txtPath.Text.Trim());
//örnek: appShortcutToDesktop("application",@"D:\FK\FK WEB SAYFAM\app_data");
}
private void btnProgramShortCut_Click(object sender, EventArgs e)
{
//sadece kısayolun isminiz girmeniz yeterli
if (txtProgramName.Text.Trim() == "")
MessageBox.Show("Kısayol ismi girmelisiniz.", "Uyarı",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
appShortcutToDesktop(txtProgramName.Text.Trim());
//örnek: appShortcutToDesktop("application");
}
/// Herhangi bir programın masaüstüne kısayolunu oluşturma
private void appShortcutToDesktop(string linkName, string path)
{
string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
try
{
using (StreamWriter writer = new StreamWriter(deskDir + "\\" + linkName + ".url"))
{
if (path.Trim() != "")
{
string app = path;
writer.WriteLine("[InternetShortcut]");
writer.WriteLine("URL=file:///" + app);
writer.WriteLine("IconIndex=0");
string icon = app.Replace('\\', '/');
writer.WriteLine("IconFile=" + icon);
writer.Flush();
}
}
}
catch (Exception)
{
MessageBox.Show("Geçersiz İşlem", "Uyarı",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
/// Eğer yaptığınız c sharp kendi kısa yolunu yapsın istiyorsanız...
private void appShortcutToDesktop(string linkName)
{
string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
try
{
using (StreamWriter writer = new StreamWriter(deskDir + "\\" + linkName + ".url"))
{
string app = System.Reflection.Assembly.GetExecutingAssembly().Location;
writer.WriteLine("[InternetShortcut]");
writer.WriteLine("URL=file:///" + app);
writer.WriteLine("IconIndex=0");
string icon = app.Replace('\\', '/');
writer.WriteLine("IconFile=" + icon);
writer.Flush();
}
}
catch (Exception)
{
MessageBox.Show("Geçersiz İşlem", "Uyarı",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void btnAc_Click(object sender, EventArgs e)
{
OpenFileDialog ac = new OpenFileDialog();
ac.Filter = " Metin Dosyaları |*.txt| Bütün Dosyalar|*.*";
if (ac.ShowDialog() == DialogResult.OK)
{
StreamReader oku = new StreamReader(ac.FileName);
//Dosyanın içini okumak için streamreader kullanılır
txtPath.Text = oku.ReadToEnd();
oku.Close();
//Dosyanın adresini text te yazdırma
txtPath.Text = ac.FileName;
}
}
}
}
Hiç yorum yok :
Yorum Gönder