So I want to directly append/write things into an existing csv-file under medias only (not first creating one locally etc...), without having to use this method: HttpContext.Current.Server.MapPath(@"~\files\" + media.Name + ".csv");
I've tried this, but of course some errors appeared, as it can't write into Uri paths or something:
var media = Umbraco.TypedMedia(einladung.SelectedCsvMedia);
if (media != null)
{
var path = Request.Url.GetLeftPart(UriPartial.Authority) + media.Url;
var data = Environment.NewLine + "\"" + Request["email"] + "\";\"" + Request["surname"] + "\";\"" + Request["name"] + "\";\""+ Request["inputTextArea"]+"\";\""+registration+"\"";
var header = "\"email\";\"firstname\";\"lastname\";\"comment\";\"register\"";
IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
var mediaFile = ApplicationContext.Current.Services.MediaService.GetById(media.Id);
if (media.GetProperty("umbracoBytes") == null || media.GetPropertyValue<int>("umbracoBytes") <= 5)
{
System.IO.File.WriteAllText(path, header);
}
System.IO.File.AppendAllText(path, data);
mediaService.Save(mediaFile);
}
Then I tried this, but it isn't a valid virtual path:
var media = Umbraco.TypedMedia(einladung.SelectedCsvMedia);
if (media != null)
{
var path = HttpContext.Current.Server.MapPath(Request.Url.GetLeftPart(UriPartial.Authority) + media.Url);
var data = Environment.NewLine + "\"" + Request["email"] + "\";\"" + Request["surname"] + "\";\"" + Request["name"] + "\";\""+ Request["inputTextArea"]+"\";\""+registration+"\"";
var header = "\"email\";\"firstname\";\"lastname\";\"comment\";\"register\"";
IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
var mediaFile = ApplicationContext.Current.Services.MediaService.GetById(media.Id);
if (media.GetProperty("umbracoBytes") == null || media.GetPropertyValue<int>("umbracoBytes") <= 5)
{
System.IO.File.WriteAllText(path, header);
}
System.IO.File.AppendAllText(path, data);
mediaService.Save(mediaFile);
}
Is there another way to write into an existing media file?
How to change content of existing media? CSV-File
So I want to directly append/write things into an existing csv-file under medias only (not first creating one locally etc...), without having to use this method:
HttpContext.Current.Server.MapPath(@"~\files\" + media.Name + ".csv");
I've tried this, but of course some errors appeared, as it can't write into Uri paths or something:
Then I tried this, but it isn't a valid virtual path:
Is there another way to write into an existing media file?
Ok I figured it out myself:
is working on a reply...