{"id":3677,"date":"2014-03-29T07:48:57","date_gmt":"2014-03-29T07:48:57","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/why-are-file-uploads-via-silverlight-2-limited-to-only-txt-files-collection-of-common-programming-errors\/"},"modified":"2014-03-29T07:48:57","modified_gmt":"2014-03-29T07:48:57","slug":"why-are-file-uploads-via-silverlight-2-limited-to-only-txt-files-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/why-are-file-uploads-via-silverlight-2-limited-to-only-txt-files-collection-of-common-programming-errors\/","title":{"rendered":"Why are file uploads via Silverlight 2 limited to only .TXT files?-Collection of common programming errors"},"content":{"rendered":"<p>I have a Silverlight 2 app that sends a byte array to a Silverlight-enabled WCF service. However, (unless I try to upload a .txt file) the service&#8217;s <code>SaveFile()<\/code> method is never reached and I get an error: &#8220;The remote server returned an error: NotFound&#8221;<\/p>\n<p>Am I missing something really obvious? Why can&#8217;t I upload .doc files? Why only .txt?<\/p>\n<p>UPDATE: I&#8217;ve tried attaching debugger for CLR exceptions, but that didn&#8217;t help. I am still not able to see any errors besides the 404. Here&#8217;s my code:<\/p>\n<p><strong>in Page.xaml.cs:<\/strong><\/p>\n<pre><code>OpenFileDialog dlg = new OpenFileDialog();\n\nif (dlg.ShowDialog().Value)\n{\n  byte[] fileContent = new byte[dlg.File.Length];\n\n  using (FileStream fs = dlg.File.OpenRead())\n  {\n    fs.Read(fileContent, 0, Convert.ToInt32(fs.Length));\n    fs.Close();\n  }\n\n  Service1.Service1Client srv = new SL1.Service1.Service1Client();\n\n  srv.SaveFileCompleted += (sender1, e1) =&gt;\n  {\n    foo.Text = \"Uploaded!\";\n  };\n\n  srv.SaveFileAsync(dlg.File.Name, fileContent);\n}\n<\/code><\/pre>\n<p><strong>in Service1.svc.cs:<\/strong><\/p>\n<pre><code>[OperationContract]\npublic string SaveFile(string fileName, byte[] fileContent)\n{\n  string ret = String.Empty;\n\n  try\n  {\n    string target = @\"c:\\debug123\\\" + fileName;\n\n    if (File.Exists(target))\n    {\n      File.Delete(target);\n    }\n\n    File.WriteAllBytes(target, fileContent);\n\n    ret = \"OK\";\n  }\n  catch (Exception ex)\n  {\n    ret = ex.ToString();\n  }\n\n  return ret;\n}\n<\/code><\/pre>\n<p>Anyone see anything wrong with this?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a Silverlight 2 app that sends a byte array to a Silverlight-enabled WCF service. However, (unless I try to upload a .txt file) the service&#8217;s SaveFile() method is never reached and I get an error: &#8220;The remote server returned an error: NotFound&#8221; Am I missing something really obvious? Why can&#8217;t I upload .doc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3677","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3677"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3677\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}