|
To add to Abhinavs reply, a couple of things:
1) When you post code, don't post the whole project - just the relevant portion. A code fragment makes it a lot more likely that your code will be read, (and responded to with relevant details) than posting the whole file. That just makes it tiresome to get to the "Reply" button if anyone wants to.
2) When you post a code fragment, use the "code block" widget, or suuround it with <pre>...</pre> tags to preserve the formatting - it does a much neater job than the dogs dinner you served up!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Aaron Radich wrote:
_tmrMain = new System.Timers.Timer();
_tmrMain.Elapsed += new ElapsedEventHandler(this.DoDrawEvent);
_tmrMain.Interval = this.RefreshRate;
_tmrMain.Start();
That's your problem. The System.Timers.Timer raises events on a ThreadPool thread unless you set it's Synchronizing Object property.
Alan.
|
|
|
|
|
Hi,
I did not read all that code, however I'm pretty sure what you need is explained here[^].
|
|
|
|
|
With a folderbrowserdialog and a textbox that shows the folder to save to, i need to put \ after.
have been trying to put it like this:
textBoxSaveToFolder + (\) or ("\") or "\"
but it doesnt work. How can that been done???
wc.DownloadFileAsync(new Uri(sFiles.Trim()), String.Format(textBoxSaveToFolder.Text + "{0}.xml", ("omgang=") + i, Path.GetExtension(sFiles)));
private void btnFolder_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBoxSaveToFolder.Text = folderBrowserDialog1.SelectedPath;
}
}
|
|
|
|
|
in languages such as C# a backslash is an escape character, it isn't taken literally; instead it gets combined with the character following it to create specials, such as a tab, a newline, etc.
if you want a real backslash, you need to:
- either have two of them
- or indicate you don't want the escape mechanism by prefixing a @
so try "a\\b" or @"a\b"
That is elementary knowledge about a programming language, something you need to pick up from reading a book on C#.
To apply this correctly in your code, I suggest you use your debugger, single-step through your code and watch at the intermediate values. And yes, Visual Studio may try and confuse you by adding some backslashes that aren't really there, so my recommendation is to really output strings to the output panel, using
Console.WriteLine(str);
That is bound to truthfully show the string content no matter what.
|
|
|
|
|
Thank you very much!
I have seen that before but didnt understood what is was good for (@).
Seems like i have missed a lot from books, i got C# beginners book but havent seen it. Or i learn very slow!
|
|
|
|
|
|
You may want to consider using Path.Combine() [^] instead of manually constructing the filename.
/ravi
|
|
|
|
|
thanks, that will be useful
|
|
|
|
|
You need to escape the character...
textBoxSaveToFolder + "\\"
Sorry, I didn't see the above answers for some reason before I submitted mine.
|
|
|
|
|
ok...I've looked around, and haven't been able to get many places with this.
(Necessary Background Information)
Essentially, the situation we are in is that users need to log into our application that is going to be sitting on a production server. The user's corporate credentials will be used to authenticate their access to our app and one of the primary functions that they are to have is a "Push Button File Push" to a Celera server that has ancillary processes running on it that are out of scope for the purposes of this post. The user will NOT be allowed to be authenticated against the Celera share, our application will.
Problem:
I need to be able to access the file server through my code via a UNC path...and in production, this server will be locked down.
I'm trying to use a NetworkCredentials instance to authenticate myself, but I am unsure exactly what System.Net object I need to use to connect to our server. WebRequest?? WebClient??
File.CreateText isn't working, because I can't find a way to provide credentials to the path.
Any help?
I am absolutely stumped!!
My code thus far looks like this (with WebRequest):
private static void WriteArchive(string document, MessageType outboundInfo, string filePath)
{
try
{
WebRequest request = UNCResource("~data/ApplicationSettings.xml");
TextWriter writer = null;
string fileName = outboundInfo.FileName;
writer = new StreamWriter(filePath + fileName);
request.
writer.Write(document);
writer.Close();
}
catch (Exception ex)
{
throw ex;
}
}
private static WebRequest UNCResource(string configurationLocation)
{
XmlDocument configuration = (new XmlDocument().Load(configurationLocation));
NetworkCredential credentials = GetNetworkCredentials(configuration);
return UNCResource(ref credentials, configuration);
}
private static WebRequest UNCResource(ref NetworkCredential credentials, XmlDocument configuration, Destination destination)
{
CredentialCache cache = new CredentialCache();
string destinationUri = String.Empty;
switch (destination)
{
case Destination.Archive:
{
destinationUri = configuration.DocumentElement.SelectSingleNode("fileArchiveLocation").InnerText;
break;
}
case Destination.Outbound:
{
destinationUri = configuration.DocumentElement.SelectSingleNode("fileSaveLocation").InnerText;
break;
}
}
cache.Add(new Uri(destinationUri), "Basic", credentials);
WebRequest server = WebRequest.Create(destinationUri);
server.Credentials = cache;
return server;
}
private static NetworkCredential GetNetworkCredentials(XmlDocument configuration)
{
XmlNode userNameNode = configuration.DocumentElement.SelectSingleNode("username");
XmlNode passwordNode = configuration.DocumentElement.SelectSingleNode("password");
XmlNode domainNode = configuration.DocumentElement.SelectSingleNode("domain");
return new NetworkCredential(userNameNode.InnerText, passwordNode.InnerText);
}
"I need build Skynet. Plz send code"
|
|
|
|
|
By the way, Configuring the app for Impersonation is a last option. I am hoping to find a solution that simply allows us a means to provide credentials to the server at run-time and drop a file into a folder that is accessible via those credentials.
Anybody have an idea how to get this done?
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi All,
I'm trying to hide/show controls which allow a user to add a new record to a DataList when the Edit button is clicked. So when the btnEdit link is clicked (please see code below) then the ddlDescAdd dropDownList show be hidden (visible = false).
Here is a snipet of my DataList:
<asp:DataList id="ItemsList"
runat="server"
...>
<ItemTemplate>
<asp:LinkButton id="btnEdit"
Text="Edit"
CommandName="Edit"
runat="server"/></td&g
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlDescAdd"
Runat="server" Width="280px" />
<asp:LinkButton id="btnAdd"
Text="Add"
CommandName="Insert"
runat="server" /> </td>
</FooterTemplate>
</asp:DataList>
Does anyone know how I can do this?
Thanks,
Mel
|
|
|
|
|
|
Thanks for your reply Jinal,
I was able to hide the footerTemplate when the edit button is clicked.
I have another problem I've came into though. When The dataList is empty I want to show only the header and footer templates, I thought I could do this with the following code:
if (dTable.Rows.Count == 0)
{
dlICD9Codes.ShowHeader = true;
dlICD9Codes.ShowFooter = true;
lblSearchStatus.Text = "count == 0";
}
else
{
dView = new DataView(dTable);
dView.Sort = "ICD9CODE";
lblSearchStatus.Text = "count != 0";
}
Do you know why the header and footer aren't showing up when the row count is zero? Do you know of a way I can get this working?
Thanks in advance,
Mel
|
|
|
|
|
|
hi,
i have developed win apps with c# and this apps basically read csv file through a map drive.
when i am running this apps just clicking on exe file name then it can read file through the map drive but when the exe of my apps is invoked by win task scheduler then application is running but fail to read the file through map drive. i am testing this apps on windows server 2008. so please anyone help me with idea that what i need to do as a result network resource will be available when my apps will be invoked by windows task scheduler. please help in detail....its urgent.
thanks in advance.
tbhattacharjee
|
|
|
|
|
Hi,
I suspect your app running through Task Scheduler isn't using your logon session and desktop, hence is unaware of your drive mappings. You probably could incorporate code to do its own drive mapping, see this CP article: Map Network Drive (API)[^]. Hope it works well for you, I haven't done this myself yet.
|
|
|
|
|
When you add a scheduled task, make sure the user you enter has sufficient privileges to access the drives to be mapped. Then you might also need to create a batch file which maps the drives with the "net use" command before starting the actual task from that batch file.
|
|
|
|
|
I want to use WMI to tell the difference between a removable media thats a memory card and a USB drive.
It would seem there is some way, because on the menu for Safely Remove Hardware you can choose to eject the disks in a card reader individually while not ejecting the hardware (a mass storage device), while for a USB drive you're choosing to eject the drive.
Brian
|
|
|
|
|
I am not 100% sure. Try reading about WM_DeviceChanged message. I hope this helps.
|
|
|
|
|
The difference is there because the card readers are usually composite devices (i.e. a device that contains other devices), while USB disks are usually (but not always) the final device.
You always eject at the final device level, which in the card reader's case, is the card. (You wouldn't want to get hit by the card reader square in the face, would you).
If you want to get rid of the whole cardreader, you'll have to disable it at the device level. Uninstall will only cause it to be re-detected at the next PNP scan).
|
|
|
|
|
How would I determine that? Just look up if there's more than one dependent drive on to the USB Mass Storage device? But I want to account for cases in which the card reader is only able to read one type of card, and I'm not sure how this is distinguishable in WMI.
|
|
|
|
|
That might prove difficult, or even impossible. This depends on the manufacturer and the driver. USUALLY the device chain will indicate separate disk drives for each card type in the card reader, but this is no guarantee. Some card readers have multi-format slots which accept more than one card format through some hardware interlocking mechanism. Whether these appear as a separate disk drive or not is entirely up to the driver. My hunch is that most drivers will show one card format per card type (except for the SD format, where even the card type cannot be determined by hardware: SD/mini-SC/micro-SD can be converted to one another with conversion sleeves).
At the end of the chain, the only thing you see is a device with USBClass Disk, and USBClass RAW. The type of disk will only be determined when a card is physically inserted into a slot.
|
|
|
|
|
I've noticed in Device Manager that the Mass Storage Devices for the multi-card readers I own have a "Bus reported device description" of "Mass Storage Device" -- a generic name -- but the one for the USB drive instead has the description of the device name.
Is this at all significant? And where does the "Bus reported device description" come from?
|
|
|
|