फॉर्म लोड इवेंट पर एंबेडेड TXT फाइल पढ़ें।
चर को गतिशील रूप से सेट करें।
string f1 = "AppName.File1.Ext";
string f2 = "AppName.File2.Ext";
string f3 = "AppName.File3.Ext";
एक कोशिश कैच को बुलाओ।
try
{
IncludeText(f1,f2,f3);
/// Pass the Resources Dynamically
/// through the call stack.
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
/// Error for if the Stream is Null.
}
शामिल करें के लिए शून्य बनाएँ (), विजुअल स्टूडियो आपके लिए यह करता है। CodeBlock को स्वतःपूर्ण करने के लिए लाइटबल्ब पर क्लिक करें।
उत्पन्न कोड ब्लॉक के अंदर निम्नलिखित रखें
संसाधन 1
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(file1))
using (StreamReader reader = new StreamReader(stream))
{
string result1 = reader.ReadToEnd();
richTextBox1.AppendText(result1 + Environment.NewLine + Environment.NewLine );
}
संसाधन 2
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(file2))
using (StreamReader reader = new StreamReader(stream))
{
string result2 = reader.ReadToEnd();
richTextBox1.AppendText(
result2 + Environment.NewLine +
Environment.NewLine );
}
संसाधन 3
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(file3))
using (StreamReader reader = new StreamReader(stream))
{
string result3 = reader.ReadToEnd();
richTextBox1.AppendText(result3);
}
यदि आप दिए गए चर को कहीं और भेजने की इच्छा रखते हैं, तो बस दूसरे फ़ंक्शन को कॉल करें और ...
using (StreamReader reader = new StreamReader(stream))
{
string result3 = reader.ReadToEnd();
///richTextBox1.AppendText(result3);
string extVar = result3;
/// another try catch here.
try {
SendVariableToLocation(extVar)
{
//// Put Code Here.
}
}
catch (Exception ex)
{
Messagebox.Show(ex.Message);
}
}
यह क्या हासिल किया गया था, एक एकल पाठ बॉक्स के अंदर कई txt फ़ाइलों को संयोजित करने और उनके एम्बेडेड डेटा को पढ़ने का तरीका। जो कोड के इस नमूने के साथ मेरा वांछित प्रभाव था।
Environment.SpecialFolder
डेस्कटॉप फ़ोल्डर प्राप्त करने के लिए एक नज़र रखना । आपको यह ध्यान रखने की आवश्यकता है कि संसाधन को परियोजना के भीतर उसके पथ के आधार पर नाम दिया जाएगा, इसलिए इसका नाम बस नहीं हो सकता हैfile1.txt
।