Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Exporting to Outlook (.ics file) from C#.Net Web Application

  • 01-06-2011 4:18pm
    #1
    Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭


    Hey everyone,

    Wondering of anyone can help on this issue.

    Basically i'm trying to create and export a .ics file from a c#.net web application. So the user can save it, and open it in Outlook to add something to their calendar.

    heres the code I have at the moment...
    string icsFile = createICSFile(description, startDate, endDate, summary);
    
    
    //Get the paths required for writing the file to a temp destination on the server. In the directory where the application runs from.
    
            string codeBase = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            string assPath = Path.GetDirectoryName(path).ToString();
    
            string fileName = emplNo + "App.ics";
            string fullPath = assPath.Substring(0, assPath.Length-4);
    
            fullPath = fullPath + @"\VTData\Calendar_Event\UserICSFiles";
    
    
            string writePath = fullPath + @"\" + fileName; //writepath is the path to the file itself
    //if the file already exists, delete it so a new one can be written
            if (File.Exists(writePath))
            {
                File.Delete(writePath);
            }
    //write the file
            using (System.IO.StreamWriter file = new System.IO.StreamWriter( writePath, true))
            {
                file.WriteLine(icsFile);
            }
    
    

    The above works perfectly. Writes the file and deletes any old ones first.

    My main issue is how to get it to the user?

    1. Redirecting the page straight to the path of the file..:
    Response.Redirect(writePath);
    
    does not work, throws the following error:
    htmlfile: Access is denied.
    

    If i copy and paste the contents of writePath, and paste it into Internet Explorer, a save file dialog box opens and allows me to download the ics file.

    2. Prompt a Save Dialog Box to Download a File
    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.ClearContent();
            response.Clear();
            response.ContentType = "text/plain";
            response.AddHeader("Content-Disposition", "inline; filename=" + fileName + ";");
            response.TransmitFile(fullPath);
            [I]response.Flush();[/I] // Error happens here
            response.End();
    
    Does not work either.
    [B]Access to the path[/B] 'C:\VT\VT-WEB MCSC\[B]*some of path omitted *[/B]\VTData\Calendar_Event\UserICSFiles' is [B]denied[/B].
    

    Access denied error again.


    Does anyone have any idea what may be the problem? Or have any other suggestions on how to do what I am trying to do....


    Thanks!


Comments

  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Is the file path within your web application ?


  • Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭Korvanica


    It is yea, Ive tried multiple places within and outside the application...


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    I must be taking you up wrong here but to me it looks like your doing a

    Response.Redirect("C:\VT\VT-WEB MCSC\*some of path omitted*\VTData\Calendar_Event\UserICSFiles\111.ics");

    Your on a web server.....

    Try Redirect to "~/VTData/Calendar_Event/UserICSFiles/111.ics"

    I really really hope I'm wrong


  • Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭Korvanica


    got it working, turns out the page I was calling it from had the button set to do a postback as soon as it was clicked.

    Which was causing the JS errors...

    Cheers for teh replys anyway!


Advertisement