|
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?
|
|
|
|
|
Educated guesswork, don't quote me on this :
Real hard disk devices have firmware, and it's the firmware that reports this. (it will usually correspond to the 'friendly device name', I think). Disk drive producers will often include free utilities (such as some backup crapware), which will only run on their kit. The software has to check if their kit is connected, and it will do that by checking this field. Often, firmware must also be updated, usually using specific IOCTLs, and the firmware update utilities must be sure they don't clobber some other manufacturer's. This field may help in checking the origin of the kit before they issue their 'zap and destroy' IOCTLs. Some USB disk assemblies also offer firmware RAID configurations, and this may help their raid configuration utilities in determining the command set to configure them.
A storage card has no firmware, and so cannot report anything here (there may be exceptions, but I haven't come across any). If there's anything firmware worth reporting, it will be at the composite device level. Anyway, a storage card can only report anything when it's inserted, so this probably wouldn't serve your purpose.
|
|
|
|
|
Actually it kind of would serve my purpose -- I just want to determine whether a logical disk is hosted by a card reader, or is hosted by a USB drive. If I could determine the 'bus reported' description for any given USB Mass Storage Device.. but I don't know how to do that.
Can you help?
|
|
|
|
|
I'll dig around a bit, don't expect anything today, bedtime coming soon in my timezone
|
|
|
|
|
Based on the devices that I have, I figured out that you can expect a USB Flash Drive to have PDCAP_D2_SUPPORTED under "Power data" in Device Manager, but not a memory card.
So I used a PInvoke to DevicePowerEnumDevices in PowrProf.dll ( http://msdn.microsoft.com/en-us/library/aa372681(VS.85).aspx[^] ). That allowed me to filter by the device name in Win32_DiskDrive.Model and the PDCAP_D2_SUPPORTED flag.
|
|
|
|