Monday, 2 September 2013

SharePoint app give web project (host web) access to documents

SharePoint app give web project (host web) access to documents

I have a provider hosted SharePoint 2013 app. In this app I have a custom
ribbon action that when clicked goes to the host web (Default.aspx). On
this page I want to create a hash for the selected document in SharePoint
with the following code:
Uri FileUri = new Uri(docUrl);
byte[] hashValue;
using (var Client = new WebClient())
{
hashValue =
SHA256Managed.Create().ComputeHash(Client.OpenRead(FileUri));
}
Label2.Text = BitConverter.ToString(hashValue).Replace("-", String.Empty);
docUrl is a string containing the url to the document in SharePoint. In
AppManifest.xml Web, SiteCollection and List all have FullControl.
When I run this I get the error 403 forbidden. Is this because the host
web does not have access to the document? How can it be fixed?

Django rest framework overwriting initial for custom logging bypasses OAuth initialisation

Django rest framework overwriting initial for custom logging bypasses
OAuth initialisation

I'm sure there must be something I don't understand about type hierarchies
and initialisation in python... I wanted to log post bodies with django
rest framework like suggested here on stackoverflow: by overriding initial
and finalize_response.
This is how my mixin looks like:
class LoggingMixin(object):
"""
Provides full logging of requests and responses
"""
def finalize_response(self, request, response, *args, **kwargs):
# do the logging
if settings.DEBUG:
logger.debug("[{0}] {1}".format(self.__class__.__name__,
response.data))
return super(LoggingMixin, self).finalize_response(request, response,
*args, **kwargs)
def initial(self, request, *args, **kwargs):
# do the logging
if settings.DEBUG:
try:
data = request._data
logger.debug("[{0}] {1}".format(self.__class__.__name__, data))
except exceptions.ParseError:
data = '[Invalid data in request]'
super(LoggingMixin, self).initial(self, request, *args, **kwargs)
And my view:
class BulkScan(LoggingMixin, generics.ListCreateAPIView):
"""
Provides get (list all) and post (single) for scans.
"""
queryset = Scan.objects.all()
serializer_class = ScanSerializer
authentication_classes = (OAuth2Authentication,)
permission_classes = (IsAuthenticated,)
# insert the user on save
def pre_save(self, obj):
for scan in obj:
scan.user = self.request.user
def post(self, request, *args, **kwargs):
serializer = ScanSerializer(data=request.DATA, many=True)
if serializer.is_valid():
self.pre_save(serializer.object)
self.object = serializer.save(force_insert=True)
self.post_save(self.object, created=True)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED,
headers=headers)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Yet, a post or get request fails, complaining that the request.user
property is not present. This must automagically be injected there. If I
don't overwrite initial then everything is fine and the user is set when
APIView.initial is called.
I don't get why the user property is not set when I override the method.
Many thanks

PHP insists on a wrong timezone

PHP insists on a wrong timezone

Here is a script with the output of each line in a comment next to each
statement to demonstrate my problem
<?php
echo date_default_timezone_get(); //Europe/Helsinki
date_default_timezone_set('Africa/Cairo');
$script_tz = date_default_timezone_get();
if (strcmp($script_tz, ini_get('date.timezone'))){
echo "\nScript timezone differs from ini-set timezone."; //True,
this block is ran
} else {
echo "\nScript timezone and ini-set timezone match.";
}
echo "\n".date_default_timezone_get(); //Africa/Cairo
echo "\n'".ini_get('date.timezone')."'"; //''
echo "\n".date('Z'); //10800
echo "\n".date("m/d/Y h:i:s A T",strtotime("-1 hour")); //I still have
to do this to obtain the correct date !
?>
I'm in Cairo where we no longer have DST for around 3 years now. The
server's timezone is set correctly and DST option isn't even available to
enable or disable DST. So it is inherently disabled. Here is a screenshot
to demonstrate

In my php.ini file
[Date]
; Defines the default timezone used by the date functions
;date.timezone =
So why do still have to manipulate the date() output (i.e. reducing it by
one hour) to get the correct time which matches the server time ?
And why does it insist that Europe/Helsinki is my timezone ?

Sunday, 1 September 2013

Unable to call Webservice (asmx) from Windows Mobile 6.5 on IIS

Unable to call Webservice (asmx) from Windows Mobile 6.5 on IIS

My asmx Service is hosted on IIS. On making request from windows mobile
6.5 browser it returns HTTP 400 BAD REQUEST. While I run this service on
local environment it works fine .... Kindly reply as soon as possible ...
thanx

XML broken links

XML broken links

I'm having a bit problem and it's been an hour finding a proper solution
online. I have a sitemap.xml file and I need to check it for broken links.
so far most of the tools that I have found are not free others broken and
others are just not working. Would really appreciate it someone would help
me out. Thanks in advance.

casting values from an array to the findViewById ids

casting values from an array to the findViewById ids

public String getTexts(int i, int j, String[][] setTexts){
String id = new String();
return id = setTexts[i][j];
}
for (int i = 0; i < weights.length; i++) {
for (int j = 0; j < weights[i].length; j++) {
final EditText setTexts[i][j] =
(EditText)findViewById(R.id.getTexts(i,j,setTexts[][]));
}
}
I used a getter to get a value from a 2d array called "setTexts" that I
created before the shown code, containing the ids of the EditTexts that I
wanted to change. Then when I tried to use the method to get the ids, I
get "unexpected tokens" and a "cannot resolve method "getTexts". I also
tried casting but it didn't work.

How does facebook update the feeds dynamically?

How does facebook update the feeds dynamically?

How does facebook update the feeds automatically without even refreshing
the page , moreover the feeds get added up on the top of the page. Which
language tho they use to make that possible?