Click here to Skip to main content
15,913,941 members
Home / Discussions / C#
   

C#

 
Questionwhere to put \ (slash)? Pin
Member 216810329-Apr-10 11:06
Member 216810329-Apr-10 11:06 
AnswerRe: where to put \ (slash)? Pin
Luc Pattyn29-Apr-10 11:34
sitebuilderLuc Pattyn29-Apr-10 11:34 
AnswerRe: where to put \ (slash)? Pin
Member 216810329-Apr-10 13:05
Member 216810329-Apr-10 13:05 
GeneralRe: where to put \ (slash)? Pin
Luc Pattyn29-Apr-10 13:59
sitebuilderLuc Pattyn29-Apr-10 13:59 
AnswerRe: where to put \ (slash)? Pin
Ravi Bhavnani29-Apr-10 13:00
professionalRavi Bhavnani29-Apr-10 13:00 
AnswerRe: where to put \ (slash)? Pin
Member 216810329-Apr-10 22:52
Member 216810329-Apr-10 22:52 
AnswerRe: where to put \ (slash)? Pin
fjdiewornncalwe30-Apr-10 2:55
professionalfjdiewornncalwe30-Apr-10 2:55 
QuestionWriting a file from a StreamWriter to a UNC path Pin
Alaric_29-Apr-10 9:51
professionalAlaric_29-Apr-10 9:51 
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");
        //File.CreateText(???)
        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"

AnswerRe: Writing a file from a StreamWriter to a UNC path Pin
Alaric_29-Apr-10 10:03
professionalAlaric_29-Apr-10 10:03 
QuestionHide/Show a control in a DataList Pin
MWRivera29-Apr-10 9:34
MWRivera29-Apr-10 9:34 
AnswerRe: Hide/Show a control in a DataList Pin
Peace ON29-Apr-10 23:50
Peace ON29-Apr-10 23:50 
GeneralRe: Hide/Show a control in a DataList Pin
MWRivera30-Apr-10 5:56
MWRivera30-Apr-10 5:56 
AnswerRe: Hide/Show a control in a DataList [modified] Pin
Peace ON2-May-10 22:51
Peace ON2-May-10 22:51 
QuestionWindows Task Schedular and Map drive problem Pin
Tridip Bhattacharjee29-Apr-10 8:52
professionalTridip Bhattacharjee29-Apr-10 8:52 
AnswerRe: Windows Task Schedular and Map drive problem Pin
Luc Pattyn29-Apr-10 8:57
sitebuilderLuc Pattyn29-Apr-10 8:57 
AnswerRe: Windows Task Schedular and Map drive problem Pin
Bernhard Hiller29-Apr-10 21:47
Bernhard Hiller29-Apr-10 21:47 
QuestionWMI and the difference between memory cards and USB drives Pin
brian.shapiro29-Apr-10 6:09
brian.shapiro29-Apr-10 6:09 
AnswerRe: WMI and the difference between memory cards and USB drives Pin
dan!sh 29-Apr-10 6:23
professional dan!sh 29-Apr-10 6:23 
AnswerRe: WMI and the difference between memory cards and USB drives Pin
Michel Godfroid29-Apr-10 23:20
Michel Godfroid29-Apr-10 23:20 
GeneralRe: WMI and the difference between memory cards and USB drives Pin
brian.shapiro1-May-10 11:52
brian.shapiro1-May-10 11:52 
GeneralRe: WMI and the difference between memory cards and USB drives Pin
Michel Godfroid1-May-10 19:31
Michel Godfroid1-May-10 19:31 
GeneralRe: WMI and the difference between memory cards and USB drives Pin
brian.shapiro5-May-10 9:44
brian.shapiro5-May-10 9:44 
GeneralRe: WMI and the difference between memory cards and USB drives Pin
Michel Godfroid5-May-10 10:32
Michel Godfroid5-May-10 10:32 
GeneralRe: WMI and the difference between memory cards and USB drives Pin
brian.shapiro5-May-10 10:34
brian.shapiro5-May-10 10:34 
GeneralRe: WMI and the difference between memory cards and USB drives Pin
Michel Godfroid5-May-10 10:42
Michel Godfroid5-May-10 10:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.