Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将SVG内容保存为c#sever上的SVG图像_C#_File_Svg - Fatal编程技术网

如何将SVG内容保存为c#sever上的SVG图像

如何将SVG内容保存为c#sever上的SVG图像,c#,file,svg,C#,File,Svg,将svg内容作为svg图像文件保存在C#服务器上时面临困难。我已经生成了svg图像,并将整个svg标记(包括矢量图像)发布到服务器。但在服务器上接收后,无法将其保存为服务器目录上的SVG图像 客户端代码: var imageData = resizedCanvas.toDataURL("image/png"); var targetSVG = document.getElementById('svg'); var encodedString = encodeURIComponent($('#sv

将svg内容作为svg图像文件保存在C#服务器上时面临困难。我已经生成了svg图像,并将整个svg标记(包括矢量图像)发布到服务器。但在服务器上接收后,无法将其保存为服务器目录上的SVG图像

客户端代码:

var imageData = resizedCanvas.toDataURL("image/png");
var targetSVG = document.getElementById('svg');
var encodedString = encodeURIComponent($('#svgContainer')[0].innerHTML);
 $.ajax({
    type: 'POST',
    url: '/CanvasSave.aspx/UploadImage',
    data: '{ "imageData" : "' + encodedString + '", "userEmail": "' + userEmail + '" , "quantity": "' + quantity + '" }',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: function (msg) {....},
    error: function (xhr) {           
        alert('Error Occured! Please try again.\n\n Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
    }
C#代码:

publicstaticstringuploadimage(stringimagedata、stringuseremail、int-quantity)
{
imageData=HttpUtility.UrlDecode(imageData);
//这里完成svg标记,图像数据接收成功。
//

// 它只是文本,所以请使用常规文本保存方法保存它:

public static string UploadImage(string imageData, string userEmail, int quantity)
{
    imageData = HttpUtility.UrlDecode(imageData);

    var completePath = @"~\user-images\file.svg";
    completePath = HttpContext.Current.Server.MapPath(completePath);

    File.WriteAllText(completePath, imageData);  // <--
}
publicstaticstringuploadimage(stringimagedata、stringuseremail、int-quantity)
{
imageData=HttpUtility.UrlDecode(imageData);
var completePath=@“~\user images\file.svg”;
completePath=HttpContext.Current.Server.MapPath(completePath);

File.writealText(completePath,imageData);//escape到底做什么?它真的做base64吗?(如果是,为什么?SVG是文本,你可以把它放到JSON中。)您不能在服务器上保存,因为您没有凭据,除非您是管理员。您需要在服务器上运行一个使用管理员凭据的应用程序才能保存。网页通常使用没有写入权限的来宾凭据运行。@jdk您到底有什么问题?错误?谢谢@Joey。是的,我使用escape对字符串进行编码。Bcoz据我所知,有必要将图像数据编码为base64字符串。您能否建议我如何将其保存到服务器上的图像文件中。@jdweng,我不完全理解您所说的内容。以前我使用canvas创建了图像绘图,并将其作为pnd图像发送到服务器上。它将是gre若你们知道如何在服务器上保存矢量图像,谢谢
public static string UploadImage(string imageData, string userEmail, int quantity)
{
    imageData = HttpUtility.UrlDecode(imageData);

    var completePath = @"~\user-images\file.svg";
    completePath = HttpContext.Current.Server.MapPath(completePath);

    File.WriteAllText(completePath, imageData);  // <--
}