I’m trying to take the base64 encrypted version of a file, decrypt it, and write the file to the server. I can’t figure out why this code isn’t working, and any help would be appreciated, as of right now I’m getting the error: File Not Found. Here’s my code:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
public void Page_Load(object sender, EventArgs e){
HttpContext c = HttpContext.Current;
//string data = Decode(c.Request["file"]);
//string name = c.Request["name"];
string name = "target.docx";
string data = Decode("SUPER LONG BASE 64, DIDNT POST BECAUSE WAY TOO LARGE");
StreamWriter writer = File.CreateText(Server.MapPath("~/services/temp/"+name));
// Error generated here, after previous line.
writer.WriteLine(data);
writer.Close();
Response.Redirect("temp/"+name);
}
public string Decode(string str){
byte[] decbuff = Convert.FromBase64String(str);
return System.Text.Encoding.UTF8.GetString(decbuff);
}
</script>
I figured it out, I needed to make a local directory off of the wwwroot since the directories created in sharepoint designer weren’t physical, here is the code.