|
I have a multi line text box, wordwrap set to true. No matter what character sequences I place at the end of each line using a hex text editor to build a text file, the text still streams when I loaded the .txt file into the text box. I have tried all combinations of trailing x'0D' x'0A'
Any ideas?
Thanks,
David
pongfar@comcast.net
|
|
|
|
|
Why are you using a hex editor? Notepad, WordPad or Word will all produce correctly formatted text files with newline sequences in the proper place.
faltopar wrote: the text still streams when I loaded the .txt file into the text box.
I'm not sure what you mean by this statement, can you explain?
|
|
|
|
|
i don't understand your mean clearly.
1)
you should use 'streamwriter' to save to file, 'streamReader' to read from file
, use(Utf-8) Encode.
2)
may be you should consider to change to right ''Hex,Octal,Binary。。。。“ before show to 'multi line text box',
after you read form file.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 22:03pm.
|
|
|
|
|
I have a C# application which uses a COM dll that was registered when some third party software was installed. So when I added a reference to it in visual studio, it naturally created an Interop.dll, and that's what I have a reference to.
My problem is that I wanted to send the program to a friend and he doesn't have that 3rd party software on his machine.
What's the best way to deal with this? I tried adding a reference to the dll file itself instead of using the COM tab, and that seemed to work, but it looks like it involves the path to that file on MY machine, which probably won't work on his side either. Copy Local is set to TRUE, but that seems to just copy in the Interop dll. I've had experience with a setup installer packaging the needed files and registering them for you, but i'd like to avoid an installer. we'll be doing rapid dev-test cycles and it's nice to be able to just 'drop-install' the files on his machine.
Anyone able to guide me on this?
|
|
|
|
|
If you send him the com dll just get him to open a cmd prompt and run regsvr32 <path_to_com_dll> .
|
|
|
|
|
Yeah, was hoping to avoid that, but it's my fallback plan.
Is that regsrvr32 file part of the visual studio SDK, or the windows SDK? And is it freely available? because i imagine i'll have to get him that as well.
|
|
|
|
|
Neither, its part of Windows.
|
|
|
|
|
Im not confirm that the regsvr32 is perfect for a dll registration which is developed by using C#.net..RegAsm command can be consider...
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
Thanks
Md. Marufuzzaman
|
|
|
|
|
Its a COM dll, not a .NET assembly.
RegAsm allows com clients to call .NET dll's. The OP was asking about accessing a COM dll from .NET
|
|
|
|
|
Apart from all the good advice from others, there is one point that you might want to consider.
That is the legality of copying the dll to your friends machine. If it came with software that you have installed, then there might be copyright issues. I'm not saying don't do it, I'm just saying is all.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I need to insert an image into a byte [] array Anybody know how to do this?
|
|
|
|
|
Message Closed
modified 23-Nov-14 10:07am.
|
|
|
|
|
Image img = Image.FromFile("FileAddress");
System.Io.MemoryStream mem=new System.Io.MemoryStream();
img.Save(mem, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] b = mem.GetBuffer();
|
|
|
|
|
hi
I want to make a program. It has an output exe file. Is it possible
writing with c#.net?
why not!?
|
|
|
|
|
If you're asking whether or not you can run your program as an executable, then you can. Right click on your project and select Properties. Choose the Application tab, and select the Output type to be Windows Application or Console Application depending on which type you intend to deploy.
If you're asking whether or not you can create an executable from your program, then you can do this as well. You need to read up on the CodeDOM[^] classes.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I mean ,I can create an executable from my program.
|
|
|
|
|
why not ??
if you set application type to ConsoleApplication / WindowsApplication, then the output is EXE.
|
|
|
|
|
|
I'm trying to make a group settings classes that read XML files and set the appropriate fields in those classes. Here are the classes I have:
SettingsBase
System1Settings : SettingsBase
System2Settings : SettingsBase
...
I also have some sub classes that grouped common settings together for easier coding.
class System1Macros
{
string macro1;
string macro2;
...
}
class System1Registers
{
string register1;
string register2;
...
}
Inside each system class, I have some fields that inherit from those classes. For example, inside System1Settings:
System1Macros macros;
System1Registers registers;
My settings.xml files have the format:
<?xml version="1.0" encoding="utf-8" ?>
<System1Settings>
<Setting name="SomeSetting1">Major1</Setting>
<Setting name="SomeSetting2">Major2</Setting>
<Setting name="SomeSetting3">Major3</Setting>
...
<Macros>
<Setting name="Macro1">1</Setting>
<Setting name="Macro2">10</Setting>
...
</Macros>
<Registers>
<Setting name="Register1">1</Setting>
<Setting name="Register2">2</Setting>
...
</Registers>
</System1Settings>
What I want to do is read in the System1Settings.xml file and set all of fields in System1Settings (the values in the first level of the xml file) and the fields in the specialized classes to the other levels of the xml file. So:
System1Settings.setting1 = SomeSetting1
System1Settings.setting2 = SomeSetting2
...
System1Settings.macros.macro1 = Macro1
System1Settings.macros.macro2 = Macro2
...
System1Settings.registers.register1 = Register1
System1Settings.registers.register2 = Register2
...
Right now I'm trying to use reflection in the SettingsBase (thinking I could write this routine once for all child classes and not have to rewrite each time I make a new settings class), but I'm not sure how to drill down through the fields in the SystemSettings classes to know which fields in the child classes are subclasses that need to be set. I thought there was a way to serialize/deserialize the XML, but I don't know that I can use the class structure I have.
Any insights, critiques, or nudge/shove/push/kick in the right direction would be appreciated.
Thank you,
Brad
Deja Moo - When you feel like you've heard the same bull before.
|
|
|
|
|
This doesn't seem like a good use of Reflection and I hope you don't usually resort to Reflection so readily.
Why not pass the section of XML to a method of the class so it can set its own fields?
Or, rather than have the macros and registers as fields of the class, make a more dynamic structure that you populate from the XML?
|
|
|
|
|
Hi,
I have creating shared add-in in C# and then am then using Shim on top of it.
Shared add-in has some user defined functins.once you type the UDFs in Excel, it will log in to server using username and password,creates sessions and get the data.
I am planning to move VSTO. Is it possible to introduce VSTO instead of Shim on top of shared add-in?
how can I do it? can any one share the thoughts?
|
|
|
|
|
Hi
I am using this code to upload a file to my server but on some computers like 1% of users it doesn't upload the file to the server. After trying to connect on that PC which has the problem, with Filezilla to my server I see that it fails to make the connection because it can't pass the SSL/TLS authentication part.
public static void Upload(string strLocalFileName,string strRemoteFileName, string strUsername, string strPassword)
{
WebRequest wreq = WebRequest.Create(HTTPloc.fileserverurl + strRemoteFileName);
FtpWebRequest ftp = (FtpWebRequest)wreq;
ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
ftp.Credentials = new NetworkCredential(strUsername, strPassword);
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.UsePassive = true;
ftp.UseBinary = true;
ftp.KeepAlive = false;
ftp.EnableSsl = true;
FileStream stream = File.OpenRead(strLocalFileName);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
Stream reqStream = ftp.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
}
The exception it throws is something like "remote computer didn't answer in the time provided" actually it defines timeout.
User tried OS reinstall but still the same problem. It has to be a problem with the things he does after installation. Any ideas? What causes a problem on SSL TLS authentication?
Thanks.
|
|
|
|
|
Good morning.
I set several global variables to be used throughout the form code and when I need to reference the strContainer in the WorkerImport_ProgressChanged event, the value is Null for some reason. It is fine in the Submit event and passed successfully to the WorkerImport_DoWork event. Any idea why the strContainer is Null? My understanding is,with Win form apps the WorkerImport_ProgressChanged event operates on the main (GUI) thread. The code is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Collections;
using System.IO;
using System.Xml.Linq;
using System.Configuration;
using System.Threading;
namespace IPControl
{
public partial class ucWAH : UserControl
{
string strContainer = String.Empty;
string strDave = String.Empty;
object[] obj;
ArrayList ar = new ArrayList();
FormFunctions ff = new FormFunctions();
UIPCMainForm uipc;
VariableDefs vd = new VariableDefs();
const string constrLocation = "Chattanooga";
const string constrSubnet = "/29 - Standard Work at Home";
const string constrRouter = "Cisco 999";
const string constrEUDepart = "Contact Center";
ArrayList arSubNetList = new ArrayList();
ArrayList arDHCPOptionList = new ArrayList();
ArrayList arDHCPPolicyList = new ArrayList();
ArrayList arAllocationTemplateList = new ArrayList();
string strWAHSuffix = ConfigurationSettings.AppSettings["WAH_SUFFIX"];
public ucWAH()
{
InitializeComponent();
}
#region Work at Home Form Events
private void ucTabs_Load(object sender, EventArgs e)
{
PwdSecurity p = new PwdSecurity();
uipc = this.Parent as UIPCMainForm;
DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
DataSet ds = new DataSet();
#region Populate Drop Downs
ds = d.FillDropDowns(1);
if (checkForEmptyDataset(ds)) return;
if (ds == null)
{
return;
}
cbLocation.DataSource = ds.Tables[0];
cbLocation.DisplayMember = vd.STR_COLUMN_NEAR_LOCATION;
cbLocation.ValueMember = vd.STR_COLUMN_LOCATION;
foreach (DataRow dr in ds.Tables[0].Rows)
{
arDHCPOptionList.Add(dr[vd.STR_COLUMN_DHCP_OPTION]);
arDHCPPolicyList.Add(dr[vd.STR_COLUMN_DHCP_POLICY]);
}
ds = null;
ds = d.FillDropDowns(2);
if (checkForEmptyDataset(ds)) return;
cbRouter.DataSource = ds.Tables[0];
cbRouter.DisplayMember = vd.STR_COLUMN_ROUTER_TYPE;
cbRouter.ValueMember = vd.STR_COLUMN_DM_VPN_CLOUD;
ds = null;
ds = d.FillDropDowns(3);
if (checkForEmptyDataset(ds)) return;
cbSubnet.DataSource = ds.Tables[0];
cbSubnet.DisplayMember = vd.STR_COLUMN_SUBNET_SIZE;
cbSubnet.ValueMember = vd.STR_COLUMN_DMVPN_SUBNET_TYPE;
foreach (DataRow dr in ds.Tables[0].Rows)
{
arSubNetList.Add(int.Parse(dr[vd.STR_COLUMN_SUBNET_BLOCK_SIZE].ToString()));
arAllocationTemplateList.Add(dr[vd.STR_COLUMN_SUBNET_ALLOCATION_TEMPLATE].ToString());
}
ds = null;
ds = d.FillDropDowns(5);
if (checkForEmptyDataset(ds)) return;
cbEndUserDepart.DataSource = ds.Tables[0];
cbEndUserDepart.DisplayMember = vd.STR_COLUMN_ROUTER_CATEGORY;
cbEndUserDepart.ValueMember = vd.STR_COLUMN_ONE_DIGIT_CODE;
string strAppConfigRouterConfigs = ConfigurationSettings.AppSettings["WAH_ROUTER_CONFIGURATION_TYPES"];
string[] strRouterConfigs = strAppConfigRouterConfigs.Split(',');
cbRouterConfig.DataSource = strRouterConfigs;
cbRouterConfig.SelectedIndex = 0;
#endregion
ff.ControlSetFocus(cbEndUserDepart);
cbEndUserDepart.SelectAll();
uipc = this.Parent as UIPCMainForm;
uipc.AcceptButton = btnSubmit;
uipc.Width = 800;
uipc.Height = 600;
#region Set up progress bar thread
#endregion
}
private void ucTabs_Leave(object sender, EventArgs e)
{
uipc.AcceptButton = null;
}
#endregion
#region Work From Home Button Events
private void btnReset_Click(object sender, EventArgs e)
{
tbRACFID.Text = string.Empty;
tbRACFID.Enabled = true;
tbUserName.Text = string.Empty;
cbEndUserDepart.Text = constrEUDepart;
cbLocation.Text = constrLocation;
cbSubnet.Text = constrSubnet;
cbRouter.Text = constrRouter;
cbRouterConfig.SelectedIndex = 0;
ff.ControlSetFocus(tbRACFID);
}
private void btnSubmit_Click(object sender, EventArgs e)
{
PwdSecurity p = new PwdSecurity();
DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
BackgroundWorker WorkerImport = new BackgroundWorker();
WorkerImport.WorkerReportsProgress = true;
WorkerImport.WorkerSupportsCancellation = true;
WorkerImport.DoWork += new DoWorkEventHandler(WorkerImport_DoWork);
WorkerImport.ProgressChanged += new ProgressChangedEventHandler(WorkerImport_ProgressChanged);
WorkerImport.RunWorkerCompleted += new RunWorkerCompletedEventHandler(WorkerImport_RunWorkerCompleted);
if (tbRACFID.Text == string.Empty)
{
MessageBox.Show("You must have a RACFID in order to continue.", "RACFID Field Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
ff.ControlSetFocus(tbRACFID);
return;
}
if (tbUserName.Text == string.Empty)
{
MessageBox.Show("You must have a User Name in order to continue.", "User Name Field Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
ff.ControlSetFocus(tbUserName);
return;
}
string strContainer = cbEndUserDepart.SelectedValue.ToString() + tbRACFID.Text.ToLower();
ArrayList ar = new ArrayList();
ar.Add(strContainer);
ar.Add(tbUserName.Text);
ar.Add(cbRouter.SelectedValue.ToString());
ar.Add(cbRouter.Text);
ar.Add(cbRouterConfig.Text);
ar.Add((int)arSubNetList[cbSubnet.SelectedIndex]);
ar.Add(cbSubnet.SelectedValue.ToString());
ar.Add(arDHCPOptionList[cbLocation.SelectedIndex].ToString());
ar.Add(arDHCPPolicyList[cbLocation.SelectedIndex].ToString());
ar.Add(arAllocationTemplateList[cbSubnet.SelectedIndex].ToString());
ar.Add(tbUserName.Text);
WorkerImport.RunWorkerAsync(ar);
#region deactivated code
#endregion
#endregion Work From Home Button Events
}
#region WorkerImport_DoWork
void WorkerImport_DoWork(object sender, DoWorkEventArgs e)
{
PwdSecurity p = new PwdSecurity();
DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
BackgroundWorker worker = (BackgroundWorker)sender;
worker.ReportProgress(0);
ar = (ArrayList)e.Argument;
string strContainer = (string)ar[0];
string tbUserName = (string)ar[1];
string cbRouter_SelectedValue = (string)ar[2];
string cbRouter_Text = (string)ar[3];
string cbRouterConfig_Text = (string)ar[4];
int arSubNetList = (int)ar[5];
string cbSubnet_SelectedValue = (string)ar[6];
string arDHCPOptionList = (string)ar[7];
string arDHCPPolicyList = (string)ar[8];
string arAllocationTemplateList = (string)ar[9];
string tbUserName2 = (string)ar[10];
obj =
d.importContainer(
strContainer,
tbUserName,
cbRouter_SelectedValue,
cbRouter_Text,
cbRouterConfig_Text,
arSubNetList,
cbSubnet_SelectedValue,
arDHCPOptionList,
arDHCPPolicyList,
arAllocationTemplateList,
tbUserName2
);
if (bool.Parse(obj[0].ToString()))
{
worker.ReportProgress(1);
}
else
{
worker.ReportProgress(2);
}
}
#endregion WorkerImport_DoWork
#region WorkerImport_ProgressChanged
void WorkerImport_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
StreamWriter SW;
XDocument xmlDoc;
switch (e.ProgressPercentage)
{
case 0:
SetProgressBarMarquee();
Cursor.Current = Cursors.WaitCursor;
break;
case 1:
SetProgressBarContinuous();
Cursor.Current = Cursors.Default;
string strMessage =
"You have successfully imported your Router information into IPControl. \r\n \r\n" +
"Would you like to procede with creating the configuration file to \r\n" +
"store on a Removable drive?" + "\r\n \r\n" +
"IMPORTANT NOTE: Please note the configuration file will be lost by answering No" + "\r\n" +
"to this question, and cannot be regenerated without considerable effort.";
DialogResult result;
result = MessageBox.Show(strMessage,
"IPControl Import Complete",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
xmlDoc = XDocument.Parse(obj[1].ToString());
XElement Results = XElement.Parse(xmlDoc.ToString());
string strFileName = strContainer + strWAHSuffix + ".txt";
#region Locate any removable drives
ArrayList alDriveLetter = new ArrayList();
foreach (System.IO.DriveInfo f in System.IO.DriveInfo.GetDrives())
{
if (f.DriveType.ToString() == "Removable")
{
alDriveLetter.Add(f.Name);
}
}
#endregion
if (alDriveLetter.Count == 1)
{
strMessage = "Removable drive " + alDriveLetter[0].ToString() + " was found. Would you " +
"like to save your configuration file to drive " + alDriveLetter[0].ToString() + "? \r\n \r\n" +
"IMPORTANT NOTE: Please note the configuration file will be lost by answering No" + "\r\n" +
"to this question, and cannot be regenerated without considerable effort.";
SetProgressBarMarquee();
result = MessageBox.Show(strMessage,
"Removable Drive Found",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
SW = File.CreateText(alDriveLetter[0].ToString() + strFileName);
foreach (XElement xe in Results.Descendants())
{
if (xe.HasElements)
{
foreach (XElement xeDesc in xe.Descendants())
{
if (xeDesc.Value != null)
{
SW.WriteLine(xeDesc.Value);
}
}
}
}
SW.Close();
SetProgressBarContinuous();
MessageBox.Show(
"Configuration file " + strFileName + " has saved to directory: " + alDriveLetter[0].ToString(),
"File Saved",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else if (result == DialogResult.No)
{
SetProgressBarContinuous();
btnReset.PerformClick();
return;
}
}
else
{
strMessage =
"More than one Removable drive was found, or no removable \r\n" +
"drives were found. After pressing OK, you will need \r\n" +
"to choose a location to save your configuration file. \r\n \r\n" +
"IMPORTANT NOTE: Please note the configuration file will be lost by Cancelling" + "\r\n" +
"when selecting your file output location.";
result = MessageBox.Show(strMessage,
"Choose location to save configuration file",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
FolderBrowserDialog fbd = new FolderBrowserDialog();
string strFolderName = string.Empty;
SetProgressBarMarquee();
DialogResult dr = fbd.ShowDialog();
if (dr == DialogResult.OK)
{
strFolderName = fbd.SelectedPath;
SW = File.CreateText(strFolderName + strFileName);
foreach (XElement xe in Results.Descendants())
{
if (xe.HasElements)
{
foreach (XElement xeDesc in xe.Descendants())
{
if (xeDesc.Value != null)
{
SW.WriteLine(xeDesc.Value);
}
}
}
}
SW.Close();
SetProgressBarContinuous();
MessageBox.Show(
"Configuration file " + strFileName + " has saved to directory: " + strFolderName,
"File Saved",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
SetProgressBarContinuous();
return;
}
}
btnReset.PerformClick();
}
break;
case 2:
SetProgressBarContinuous();
Cursor.Current = Cursors.Default;
btnReset.PerformClick();
break;
}
}
#endregion WorkerImport_ProgressChanged
#region WorkerImport_RunWorkerCompleted
void WorkerImport_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
#endregion WorkerImport_RunWorkerCompleted
#region Work From Home field events
private void tbUserName_Enter(object sender, EventArgs e)
{
tbRACFID.Enabled = false;
if (tbRACFID.Text == string.Empty)
{
MessageBox.Show("You must have a RACFID in order to continue.", "RACFID Field Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
tbRACFID.Enabled = true;
ff.ControlSetFocus(tbRACFID);
return;
}
EEInfo ee = new EEInfo();
string strName = String.Empty;
Cursor.Current = Cursors.WaitCursor;
try
{
ee.EE(tbRACFID.Text.ToUpper());
if (ee.StrPreferredFirstName == string.Empty && ee.StrLastName == string.Empty)
{
Cursor.Current = Cursors.Default;
string strMessage =
"The RACFID or LAN ID you entered is not a valid ID. \r\n \r\n" +
"Would you like to continue with the ID you entered?";
DialogResult result;
result = MessageBox.Show(strMessage,
"RACFID/Lan ID not Found",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
tbRACFID.Text = Regex.Replace(tbRACFID.Text, @"[^\w\.]|_", "");
ff.ControlSetFocus(tbUserName);
}
else
{
tbRACFID.SelectAll();
tbRACFID.Enabled = true;
ff.ControlSetFocus(tbRACFID);
}
}
else
{
tbRACFID.Text = Regex.Replace(tbRACFID.Text, @"[^\w\.]|_", "");
tbUserName.Text = ee.StrPreferredFirstName + " " + ee.StrLastName;
ff.ControlSetFocus(cbLocation);
}
}
catch (Exception ex)
{
Cursor.Current = Cursors.Default;
MessageBox.Show(
"tbUserName_Enter method error. \n\r \n\r" + ex.Message,
"Error in User Name Routine",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
#endregion
private bool checkForEmptyDataset(DataSet ds)
{
bool booEmpty = false;
if (ds.Tables.Count < 1)
{
uipc = this.Parent as UIPCMainForm;
uipc.Width = 800;
uipc.Height = 600;
booEmpty = true;
}
return booEmpty;
}
private void SetProgressBarMarquee()
{
uipc.progressBar1.Style = ProgressBarStyle.Marquee;
uipc.progressBar1.MarqueeAnimationSpeed = 50;
}
private void SetProgressBarContinuous()
{
uipc.progressBar1.Style = ProgressBarStyle.Continuous;
uipc.progressBar1.Value = 0;
}
}
}
Thank you for taking the time to peruse this post. WHEELS
|
|
|
|
|
This may or may not be the cause of your problem - there's way too much code there to plough through to be sure...
In your DoWork handler your creating a local variable strContainer and not using the global one
string strContainer = (string)ar[0]; If you meant to use the global one just drop the string at the start
strContainer = (string)ar[0];
|
|
|
|
|
Hi Dave.
That's exactly what happened. When I removed the 'string', it displayed correctly. Very strange.
Sorry for the huge posting everyone.
Have a great day,
WHEELS
|
|
|
|
|