Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by AVividLight · Dec 26, 2011 at 04:59 AM · c#standalone.netpermissionssystem.io

Gain access to directory

Hey guys, I am trying to write a code that downloads "extra" content to the users computer after the application has been downloaded (to reduce download time and save space). So far I have only researched it, and attempted to try with a copy-and-pasted bit of code. I am getting an "UnauthorizedAccessException", so I asume that I can't download a file from the internet without the users permission; and thats why I am writing this question.

My code (mainly from http://www.csharp-examples.net/download-files) as well as the error I am currently getting are at the bottom, respectively.

 using System;
 using System.IO;
 using System.Net;
 using UnityEngine;
 using System.Security.AccessControl;
 //Written by Gibson Bethke
 public class Download : MonoBehaviour {
     
     static public string newFile = "/Users/" + Environment.UserName + "/Desktop/Downloads";
 
     void Start () {
         print(newFile);
         if (Directory.Exists(newFile)) {
         } else {
             Directory.CreateDirectory (newFile);
         }
     }
     
     void OnGUI () {
         if (GUI.Button(new Rect(1300,875,100,50), "Download")) {
             WebClient webClient = new WebClient();
             webClient.DownloadFile("http://db.tt/qXWBNu3g", newFile);
         }
     }
 }


 UnauthorizedAccessException: Access to the path '/Users/************/Desktop/Downloads' is denied.
 System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options)
 System.IO.FileStream..ctor (System.String path, FileMode mode)
 (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode)
 System.Net.WebClient.DownloadFileCore (System.Uri address, System.String fileName, System.Object userToken)
 System.Net.WebClient.DownloadFile (System.Uri address, System.String fileName)
 Rethrow as WebException: An error occurred performing a WebClient request.
 System.Net.WebClient.DownloadFile (System.Uri address, System.String fileName)
 System.Net.WebClient.DownloadFile (System.String address, System.String fileName)
 (wrapper remoting-invoke-with-check) System.Net.WebClient:DownloadFile (string,string)
 Download.OnGUI () (at Assets/Download From Web/Download.cs:22)


So, if anyone has any advice, I will really appreciate if you share it with us/me.

Thanks for all your help! Gibson

P.S. I am aware that the file I am currently trying to download is not "extra" content, but a hand-drawn image of a pony. P.P.S. I am not trying to do this in/with a web player; I am trying it in the engine itself, and I intend to use it in a standalone.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Rod-Green · Dec 26, 2011 at 10:04 PM

I suspect you are running into basic unity player permission issues. You can't download to a user dir through a web build of the game. Which is what I assuming you're trying to do here. You can download a package and use it directly but there's no way to save it locally via webbuild/deployed builds.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AVividLight · Dec 27, 2011 at 03:56 AM 1
Share

Hey Rod Green, unfortunately I am not trying to do this with the web player, I am just trying it in the engine itself, and I plan on using it in a standalone. Thanks for your prompt reply, though... I probably should have mentioned that it was for a standalone in my original question.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

how can i use ZipArchive class ,How can i use .net ZipArchive Class 0 Answers

Printing in Unity 1 Answer

custom startup resolution window 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges